Write a program that asks the user to enter a five digit number (e.g., 54321). A
ID: 3641021 • Letter: W
Question
Write a program that asks the user to enter a five digit number (e.g., 54321). After the user has done that, please have your program do the following:1) Print out those digits with two spaces between each digit.
2) Create a string that has the same digits reversed and print that out.
3) Calculate the sum of the digits and print that out.
As in Program #1, each of the results specified above should be on its own line in the output. In each case, print out a string that identifies the item to be printed, followed by the item.
For this example, your output will look like:
Digits with spaces: 5 4 3 2 1
Number in reverse: 12345
Sum of digits: 15
Hints on solving these problems:
1) If you use the nextInt() method of the Scanner class to get the number, the result will be an integer. You can convert that integer to a String with the following method:
int inputNum = keyboard.nextInt();
String numStr = Integer.toString (inputNum);
If you use the JOptionPane.showInputDialog() method, the result will already be a String.
2) In general, characters cannot be concatenated. Thus, the following statement will cause an error:
String str1 =
Explanation / Answer
Here you go: Link: - Numbers.java --> http://bit.ly/H8XEUxRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.