I want to write a method that checks if a given input is spelled like a first name.
For example: The input "Jim" should return true (or in my code "okay"), while "pam" or even "pAM" should return false ("erro" in my code).
Right now, the method always just returns "erro".
ch1 = name.charAt(characterIndex);
while (loop <= numChars) { // numChars is the length of the word I put in, loop being what letter I start at.
for (int i = 97; i < 123; i++) { // goes through the ASCII values for all the lowercase letters. 97 = a, 122 = z {
if (ch1 == i) // ch1 is the character that is currently being checked.
continue;
else { // THE ISSUE
answer = "Erro"; // "Erro" is short for "Error" which I will check for in my implementing of the code
break;
}
}
if (answer != "Erro") { // checking if I get an error or not
loop++;
characterIndex++;
ch1 = name.charAt(characterIndex);
} else {
break;
}
}
if (answer != "Erro")
answer = "okay"; // I could have put anything here, but this is when things go right.
return answer; // I keep getting the result of Error, even when I explicitly give it an 'a'