Merge pull request #5770 from amit2103/BAEL-10780
[BAEL-10780] - Added code for the checking string input article
This commit is contained in:
commit
2f9fee0391
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue