Answers for "how to check is a string is a number java"

8

java test if a string is a int

public static boolean isInt(String str) {
	
  	try {
      	@SuppressWarnings("unused")
    	int x = Integer.parseInt(str);
      	return true; //String is an Integer
	} catch (NumberFormatException e) {
    	return false; //String is not an Integer
	}
  	
}
Posted by: Guest on May-28-2020
0

check if string is decimal java

Scanner in = new Scanner(System.in);
		
		String ip1 = in.nextLine();
		
		if( ip1.matches("^\\d+\\.\\d+") ) 
			System.out.println(ip1+"----is a decimal number");
		else
			System.out.println(ip1+"----is a not decimal number");
Posted by: Guest on May-11-2020

Code answers related to "how to check is a string is a number java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language