Question
Create a new Java class called: DigitReverse Write a Java application program that will get an integer from the keyboard. Your program should then break
Create a new Java class called: DigitReverse
Write a Java application program that will get an integer from the keyboard. Your program should then break up the integer into individual digits (using some simple math) and print them to the screen in reverse order, with each digit appearing on a separate line.
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:
Please enter an integer: 57321 Your number printed in reverse order is: 1 2 3 7 5
Here is another example run of the program:
Please enter an integer: 57 Your number printed in reverse order is: 7 5
The user can enter as many digits as he/she wants (up to the size limit of the variable, of course). The data type for the variable which holds the user input should be long. This will safely allow the user to enter a number that is up to 18 digits.
Program Requirements
You are not allowed to use any String variables in this program.
You are not allowed convert the number to a String!
You must do math to split the integer number into it's individual digits.
If the user enters a negative number, you should change it to a positive number before beginning to print anything to the screen. This can be done with the "Math.abs" method. For example, the following command will put a positive 5 into the variable x:
x = Math.abs(-5);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started