borkins

06. Number in Range 1...100

Apr 12th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. /**
  2.  * Project: Advanced_Loops - created by borkins on 2017-04-08.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _06_NumberInRange_1_100
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int num;
  14.        
  15.         while (true)
  16.         {
  17.             System.out.print("Enter a number in the range [1...100]: ");
  18.            
  19.             num = Integer.parseInt(console.nextLine());
  20.             if (num > 0 && num <= 100) break;
  21.            
  22.             System.out.println("Invalid number!");
  23.         }
  24.         System.out.println("The number is: " + num);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment