Question: In java Read in a four - digit integer from the user and print out each digit on a separate line, from the most significant

In java Read in a four-digit integer from the user and print out each digit on a separate line, from the most significant (leftmost) one to the least significant (rightmost). You should use integer division and the modulo (remainder) operator to deconstruct the number and print it out piece by piece. You may use as many variables as youd like. You cannot convert the number into any other data type or use techniques beyond Chapter 3.
Hint: the remainder of any number, when divided by 10, is the rightmost digit. E.g.,9875%10 is 5. When divided by 10(using integer division), the quotient of any number is all the digits except the rightmost. E.g.,9875/10 is 987.
After you get the number-chopping part working, add input validation for the user input by adding an if-statement. If the number you read is four digits, execute all the chopping code you wrote. If the number is less than four digits, print too small and end the program. If the number is larger than four digits, print too large and end the program. Hint: four-digit numbers are at least 1000 and at most 9999.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!