I am trying to loop through a string and check each character if one of the characters is a number. If it is a number, I want to return it as true. I have a string \"crash\"
I just ran that code and I get false
, as expected. Please double-check that you’re running it correctly.
Here’s a simpler way to express that function, by the way:
public boolean isNumber(String string) {
for (int i = 0; i < string.length(); i++) {
if (!Character.isDigit(string.charAt(i))) {
return false;
}
}
return true;
}