[BAEL-10780] - Added code for the checking string input article

This commit is contained in:
amit2103 2018-11-25 01:25:41 +05:30
parent 509f2ac698
commit bff2c6f5b0
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package com.baeldung.string.checkinputs;
import java.util.Scanner;
public class CheckIntegerInput {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.println("Enter an integer : ");
if (scanner.hasNextInt()) {
System.out.println("You entered : " + scanner.nextInt());
} else {
System.out.println("The input is not an integer");
}
}
}
}