Merge pull request #5770 from amit2103/BAEL-10780

[BAEL-10780] - Added code for the checking string input article
This commit is contained in:
Loredana Crusoveanu 2018-11-25 11:40:54 +02:00 committed by GitHub
commit 2f9fee0391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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");
}
}
}
}