vendredi 20 mars 2015

"i " cannot be resolved as a variable [on hold]

With this section of code I am trying to solve the problem of determining the type of the palindrome and return either “word”, “phrase”, “number”. The definition is number is all digits, a word is all alphabetic, and a phrase is anything else.


I have tried many other ways of accomplishing this and yet I have not been able to make it to where "i" can be resolved as a variable and I do not understand why this is not working.


The program will not compile without this being fixed.



public static String getPalType(String str)
{
int numbers;
int total;

for (int i = 0; i < str.length(); i++)
{
if (Character.isDigit(str.charAt(i) == true)) // This is where the problem occurs
{
numbers++;
}
else
{
return "word";
}
if (numbers == total)
{
return "number";
}
else
{
return "phrase";
}
}

Aucun commentaire:

Enregistrer un commentaire