I'm trying to write a method that checks if a string has only numbers in it. For some reason it returns false even if I input a string containing "1234". I'm guessing my problem is with the if statement, but I'm not sure what to do to fix it.
public static boolean isNumeric(String input)
{
input.trim();
for (int count=0; count<=input.length(); count++)
{
if (input.substring(count) == "0" || input.substring(count) == "1"||
input.substring(count) == "2" || input.substring(count) == "3" ||
input.substring(count) == "4" || input.substring(count) == "5" ||
input.substring(count) == "6" || input.substring(count) == "7" ||
input.substring(count) == "8" || input.substring(count) == "9")
{
integerstate = true;
}
else
{
integerstate = false;
break;
}
}
return integerstate;
}
Does anyone see what the problem is?