Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to enter a series of one-digitnumbers (you wi

ID: 3615475 • Letter: W

Question

Write a program that asks the user to enter a series of one-digitnumbers (you will need to do error
checking). When they have finished (you will have todetermine how the user indicates they are
finished), print out how many of each number the userentered. 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 eachdigit.

Note: Do not output a value of 0 for the number of digitsentered.

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)

Explanation / Answer

// Hope this will help you, hereis Lab10_ex2.java
import java.util.*;
public class Lab10_ex2 {    public static void main(String[]args)    { int [] arr=new int[10]; int n; int i; for(i=0;i<10;i++) arr[i]=0; Scanner keyboard = new Scanner(System.in); while(true) { System.out.print("Enter a one-digit number or 10 toexit:"); n = keyboard.nextInt(); if(n>=0 && n<=9) arr[n]++; if(n==10) break; } for(i=0;i<=9;i++) System.out.println("You entered " + arr[i] + " (" + i +")");
   } } import java.util.*;
public class Lab10_ex2 {    public static void main(String[]args)    { int [] arr=new int[10]; int n; int i; for(i=0;i<10;i++) arr[i]=0; Scanner keyboard = new Scanner(System.in); while(true) { System.out.print("Enter a one-digit number or 10 toexit:"); n = keyboard.nextInt(); if(n>=0 && n<=9) arr[n]++; if(n==10) break; } for(i=0;i<=9;i++) System.out.println("You entered " + arr[i] + " (" + i +")");
   } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote