Programs to check whether the given number is an Integer or not:
package quipoin.javaeasyprograms;
import java.util.Scanner;
public class IntegerOrNot {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number:");
String s = sc.nextLine();
try {
Integer.parseInt(s);
System.out.println(s + " is an Integer");
} catch (NumberFormatException e) {
System.out.println(s + " is not an Integer");
}
sc.close();
}
}
Output:
Enter the number:
125
125 is an Integer
Enter the number:
552a
552a is not an Integer
Enter the number:
55.2
55.2 is not an Integer