[BAEL-10780] - Added code for the checking string input article
This commit is contained in:
parent
509f2ac698
commit
bff2c6f5b0
@ -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…
x
Reference in New Issue
Block a user