Question: Write a Java application program that will read a single integer value from the keyboard, and then break the number down into its individual digits.
Write a Java application program that will read a single integer value from the keyboard, and then break the number down into its individual digits.
You should begin your program should begin by declaring four separate integer variables. Name them: hundreds, tens, ones and originalNum. You can declare more if you need but all of your variables must be of data type int. Next, ask the user to enter the number. Store the inputted number in the variable originalNum. Next, perform the computation so that the hundreds, tens and ones variables will be holding the individual digits of the number. Print the final answers.
For example, if the user enters 527 for the number, when your program finishes, the hundreds variable should be holding 5, the tens variable should be holding 2, and the ones variable should be holding 7.
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:
Enter a three-digit positive integer: 765 The hundreds digit is: 7 The tens digit is: 6 The ones digit is: 5
Calculation Hint: When dividing integers, JAVA can give you both the quotient and the remainder from performing long division; however, these must be computed using two separate calculations. The forward slash mark ( / ) is the division operator and the percent sign ( % ) is the modulus operator, which returns the remainder.
For example: If you divide 5 by 3, you get a quotient of 1, with a remainder of 2. So if you if perform the calculation: 5/3 you will get the answer 1 (which is the quotient) and if you if perform the calculation: 5%3 you will get the answer 2 (which is the remainder)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
