mercredi 18 mars 2015

How do I find out if a number is an integer in this expression?

What I'm trying to do is determine if a certain number is an integer in an expression like this. (10 * 2) + 5. If the expression was (10 * 2) + 5.24 then I want the program to say that there's a non-integer in that expression. What I have right now is this:



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 there is alot 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.


Aucun commentaire:

Enregistrer un commentaire