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.
java
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
This is a popular solution!
Step by step
Solved in 3 steps with 2 images