Skip to content

Commit 2f9fee0

Browse files
authored
Merge pull request eugenp#5770 from amit2103/BAEL-10780
[BAEL-10780] - Added code for the checking string input article
2 parents 3c3d484 + bff2c6f commit 2f9fee0

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)