Advertisement
KeeganT

Ch4Ex7 v2

Feb 6th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package ch4ex7;
  2. import java.util.Scanner;
  3.  
  4. public class Ch4Ex7
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner sc=new Scanner(System.in);
  9.         int num;
  10.         System.out.print("Enter a three-digit number: ");
  11.         num=sc.nextInt();
  12.         while(num>999)
  13.         {
  14.             System.out.print("Invalid number. Please enter a three-digit number: ");
  15.             num=sc.nextInt();
  16.         }
  17.         int hundreds=num/100;
  18.         int tens=(num-(hundreds*100))/10;
  19.         int ones=num-(hundreds*100)-(tens*10);
  20.         System.out.println("The hundreds-place digit is: "+hundreds);
  21.         System.out.println("The tens-place digit is: "+tens);
  22.         System.out.println("The ones-place digit is: "+ones);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement