java forcing user to input int

Solutions on MaxInterview for java forcing user to input int by the best coders in the world

showing results for - "java forcing user to input int"
Facundo
17 Oct 2020
1boolean badNumber;
2Scanner sc = new Scanner(System.in);
3do{
4  System.out.print("Please print your number: ");
5  try{
6    int i = sc.nextInt(); 
7    System.out.println("Your Number is: " + i);
8    badNumber = false;
9  }
10  catch(Exception e){
11    System.out.println("Bad number");
12    sc.next();
13    badNumber = true
14  }
15}while(badNumber);
16
similar questions
queries leading to this page
java forcing user to input int