I am trying to practice string manipulation skills and I came up with this as a solution to check a string array for every word that ends in 'y' or 'z' (a word being defined as a string of characters separated by a space) but its wrong obviously. What can I do to resolve this error?
static int wordEndYZ(String str)
{
int i, j, counter;
for( i = 0; i < str.length(); i++ ) // search through string array
{
j=i; // copy position so original position intact
while ( str[j] == ' ' ) // *First error* space occurs, check last letter
{
if ( str[j-1] == 'y' || 'x' ) // 'y' or 'z'? If so counter increments
counter += 1;
}
}
return counter;
}
Aucun commentaire:
Enregistrer un commentaire