how to check if an input is an integer java

Solutions on MaxInterview for how to check if an input is an integer java by the best coders in the world

showing results for - "how to check if an input is an integer java"
Thiago
26 Mar 2019
1import java.util.InputMismatchException;
2import java.util.Scanner;
3
4public class Number {
5	
6	public static void main(String[] args) {
7		
8		int yourNumber;
9		
10		while(true) {	
11			
12			// to read inputs from user
13			Scanner scan = new Scanner(System.in);
14			
15			try {
16				System.out.print("ayy bruh enter you age : ");
17				
18				// throws InputMismatchException if it's not a number
19				yourNumber = scan.nextInt(); 
20				
21				scan.close();
22				break;
23			}catch(InputMismatchException notNumber) { // << catch the exception and print the error message
24				System.err.println("huh I can understand numbers,"
25						+ "ENTER A NUMBER !");
26			}
27		}
28		
29		// print the result :))
30		System.out.printf("so your age is %d, ..AWESOME !! :))", yourNumber);
31		
32	}
33	
34}
35
queries leading to this page
check if is user input is an integer javahow to check if input is int javahow to check if an input is a number in javahow to check a input is a intjava 8 check input is integercheck if input is integer javajava check if input is integercheck if user input is integer javahow to check integer input if not integer javahow to make sure input is an integer javacheck if input is not integer javatest if input is integer javajava check if input is int text inputhow to check if input is an integer or string javajava prog to check if input is numbercheck input is number javavalidate if the input is an integer in javahow to ask if input is an integer i javajava how to check if input is a numberjava program to check if input is integerhow to check if entered value is integer in javahow to check if an input is an integer javajava ensure input is integerjava check input is integerwhat is value of integer if not input in javahow to check if entered number is an int in javaif input is not int javajava check if input is intvalidate if user entered int javacheck if input in text field is int onlu in javahow to check is the input is a inthow to check if input contains integer in javahow to validate integer input in javacheck if input is number javajava check if field is integerhow to check if inputted number is an intcheck if the input is a number in javacheck if user input integer javavalidate the input int javacheck whether input is integer in javacheck int input javaprogram to check if input is an integer or a string in javahow to check if user input is an integer in javacheck if value entered is an integer javajava test input for integerif input not integer javacheck if input is integer in javajava check if input is integer or stringhow to check input is integer in javajava check input is integer javjava check if input is real numberjava checking if input is not an inthow to check if an input is an integer java