java program that asks the user to enter a number to be tested for repeated digits. For each input number from the user, the program prints a table showing how many times each digit appears in the number. Let’s assume that the appearance of a digit will not be over 1000 times in the input. Make sure your table printout can align well. The program should terminate when the user enters a number that is less than or equal to 0. A sample output is shown in the attachment.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter3: Coding With Variables, Named Constants, And Calculations
Section: Chapter Questions
Problem 4MQ1
icon
Related questions
Question

java program that asks the user to enter a number to be tested for repeated digits. For each input number from the user, the program prints a table showing how many times each digit appears in the number. Let’s assume that the appearance of a digit will not be over 1000 times in the input. Make sure your table printout can align well.

The program should terminate when the user enters a number that is less than or equal to 0. A sample output is shown in the attachment.
Enter a number: 1223
0 1 2 3 4 5 6 7 8 9
0 1 2 1 0 0 0 0 0 0
Digit:
Occurrences:
Enter a number:
67789
Digit:
0 1 2 3 4 5 6 7 8 9
0 0 0 0 0 0 1 2 1 1
Occurrences:
Enter a number:
Transcribed Image Text:Enter a number: 1223 0 1 2 3 4 5 6 7 8 9 0 1 2 1 0 0 0 0 0 0 Digit: Occurrences: Enter a number: 67789 Digit: 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 1 2 1 1 Occurrences: Enter a number:
Expert Solution
Step 1

Description:

1- In this assignment, need to take the input from the user using the java scanner class.

2 - create a variable like a num and a store user input value in that num variable. 

3- Then need to check that the user input value less than equal to zero or not. 

4- If a value less than or equal to zero then the program needs to terminate immediately else continue further. 

5- Now create a separate method for calculating how many times each digit appears. Don't write all the logic inside the java main method. This is not a good approach therefore create a separate method and write all the logic inside that method. 

6- Create a for loop (0 to 9) so it will check user values from zero to nine.

7- charAt() this is a predefined method of java string class. This method returns a string character one by one. The starting index from zero.

8- Please check the following complete example with the output screenshot. 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning