Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions