I'm trying to determine if a number is an integer in an expression like this. (10 * 2) + 5. If the expression was (10 * 2) + 5.24 I want the program to say that there's a non-integer in that expression. Current code:
public static boolean isInt(String expr) {
for (int i = 0; i<expr.length(); i++){
if (expr. charAt(i) != (int)i){
return false;
}
}
return true;
}
The problem is that there are a lot more characters besides just numbers. So I want it to just check the numbers and ignore all the other symbols to determine if every number in the string is an integer.