Example 1:
String s = "Hello World 2023";
while (scanner.hasNext()) {
if (scanner.hasNextInt()) {
System.out.println("Found Int value :" + scanner.nextInt());
}
else {
System.out.println("Not found Int value :" + scanner.next());
}
}
scanner.close();
Output:
Not found Int value : Hello
Not found Int value : World
Found Int value : 2023
Example 2:
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
scan.close();
System.out.println(a);
System.out.println(b);
System.out.println(c);