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 think this code should work, but to my mind, setting a variable and then breaking just to return it is ugly. (I know other coders like this; IMHO they are wrong.) I also dislike introducing unnecessary test variables, like NullUserException's solution. I would just return directly.
[EDIT: This code is the same as Brockman's]
public boolean isNumber() /* Note: returns true for empty string */
{
String newString = "crash";
for (int i=0; i