galinyotsev123

ProgBasics05while-Loop-P01numberInRange1to100

Jan 6th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class P01numberInRange1to100 {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. System.out.print("Еnter a number in the range [1...100]: ");
  9.  
  10. int commandNumber = Integer.parseInt(scanner.nextLine());
  11.  
  12. while(commandNumber < 1 || commandNumber > 100){
  13. System.out.println("Invalid number!");
  14. System.out.print("Еnter a number in the range [1...100]: ");
  15. commandNumber = Integer.parseInt(scanner.nextLine());
  16.  
  17. }
  18.  
  19. System.out.println("The number is: " + commandNumber);
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment