Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch4ex7;
- import java.util.Scanner;
- public class Ch4Ex7
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- int num;
- System.out.print("Enter a three-digit number: ");
- num=sc.nextInt();
- while(num>999)
- {
- System.out.print("Invalid number. Please enter a three-digit number: ");
- num=sc.nextInt();
- }
- int hundreds=num/100;
- int tens=(num-(hundreds*100))/10;
- int ones=num-(hundreds*100)-(tens*10);
- System.out.println("The hundreds-place digit is: "+hundreds);
- System.out.println("The tens-place digit is: "+tens);
- System.out.println("The ones-place digit is: "+ones);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement