View the step-by-step solution to:

Write a program that asks the user to enter a series of one-digit numbers (you will need to do error checking).

Write a program that asks the user to enter a series of one-digit numbers (you will need to do error checking). When they have finished (you will have to determine how the user indicates they are finished), print out how many of each number the user entered. There must be two methods. Name your program Lab10_ex2.java.
Here is a sample output if the user entered 0,7,7,2,7,10:
Hint: Use an array to hold an accumulator (counter) for each digit.
Note: Do not output a value of 0 for the number of digits entered.
Enter a one-digit number or 10 to exit: 0 [enter]
Enter a one-digit number or 10 to exit: 7 [enter]
Enter a one-digit number or 10 to exit: 7 [enter]
Enter a one-digit number or 10 to exit: 2 [enter]
Enter a one-digit number or 10 to exit: 7 [enter]
Enter a one-digit number or 10 to exit: 10 [enter]
You entered 1, 0(s)
You entered 1, 2(s)
You entered 3, 7(s)
Arrays of Reference Variables
You can create arrays of any data type. If the array is formed from data that uses reference variables (like Strings, for instance) then the array declaration takes two steps. The first step creates the collection of reference variables. The second step initializes each reference variable in the collection prior to using the array. If the array were an array of Strings, then the code could look something like:
String [] strings = new String[5];
strings[0] = “One”;
strings[1] = “Two”;
strings[2] = “Three”;
strings[3] = “Four”;
strings[4] = “Five”;
It is possible to initialize the array at declare time (just like any other array) or to read values into each element instead of assigning a value to each element as in the sample code above.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question