import java.util.Scanner; /** * Program to parse a number into 3 parts: hundreds, tens, and units. * * @author Steven Karas */ public class NumberParser { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // Get the number from the user System.out.print("Enter a number: "); int number = scan.nextInt(); /* * There are many many ways to do this. Your solution may be better than * this one. * * For example, you could change number with each step, to reduce the * number of operations per line. */ // break it up into hundreds, tens, and units. int hundreds = number / 100; int tens = (number / 10) % 10; int units = number % 10; // output the parsing result System.out.println(hundreds + " hundreds, " + tens + " tens, and " + units + " units."); } }