Advertisement
hpilo

Chapter2_SyntaxB_Ex6

Dec 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.           Chapter 2: Syntax section B- Loops
  5.  
  6.             Ex6: Triple digit number input
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         int number;
  15.         Scanner s=new Scanner(System.in);
  16.  
  17.         //user input
  18.         System.out.println("Enter a Triple digit number: ");
  19.         number=s.nextInt();
  20.  
  21.         //loop until Triple digit number input
  22.         while(number<100 || number>999) {
  23.             System.out.println("Try again: ");
  24.             number=s.nextInt();
  25.         }
  26.  
  27.         //display message for user
  28.         System.out.println("Triple digit number!\n***End***");
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement