Gav
2
Q:

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
	}
  	
}
1
//"% (modulo)" calulates the remainder when the value on the left is divided by the value on the right

float number = 20;

if(number%1 == 0){
	println("It is an integer");
} else {
	println("It is not an integer");
}
0

New to Communities?

Join the community