scanner check if int

Solutions on MaxInterview for scanner check if int by the best coders in the world

showing results for - "scanner check if int"
Veronica
17 Sep 2016
1boolean isAnInt = scanner.hasNextInt();
Nola
30 Jul 2020
1Scanner sc = new Scanner(System.in);
2int number;
3do {
4    System.out.println("Please enter a positive number!");
5    while (!sc.hasNextInt()) {
6        System.out.println("That's not a number!");
7        sc.next(); // this is important!
8    }
9    number = sc.nextInt();
10} while (number <= 0);
11System.out.println("Thank you! Got " + number);