Skip to content

Commit bff2c6f

Browse files
committed
[BAEL-10780] - Added code for the checking string input article
1 parent 509f2ac commit bff2c6f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.string.checkinputs;
2+
3+
import java.util.Scanner;
4+
5+
public class CheckIntegerInput {
6+
7+
public static void main(String[] args) {
8+
9+
try (Scanner scanner = new Scanner(System.in)) {
10+
System.out.println("Enter an integer : ");
11+
12+
if (scanner.hasNextInt()) {
13+
System.out.println("You entered : " + scanner.nextInt());
14+
} else {
15+
System.out.println("The input is not an integer");
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)