I have an if/else inside of a for loop designed to swap between the two based on a changing user input. The input works fine, it can do either loop, the stuff I'm comparing to choose between if/else is working, it can do either path individually but not swap between the two. Basically, it should do one if it finds a letter in a list (the letter is definitely getting into the list) and if it doesn't it does the else. My CS teacher is stumped as am I.
I've ensured that the inputs are actually making it through, the comparison works when isolated but when actually attached. I've tried swapping my else/if, I've tried changing the index from != -1 to all manner of other things like > 0, < 0, and more
public void printWord()
{
for (int i = 0; i < wordKey.length(); i++)
{
char curChar = wordKey.charAt(i);
if(letterList.indexOf(curChar) < 0)
{
System.out.print("_" + " ");
}
else
{
System.out.print(curChar + " ");
//if(win condition: every letter guessed)
}
wordKey is just a string (in this case jazz) and letterList is an arraylist with individual letters. (its supposed to be user input which is why its an arraylist)
Either I get _ _ _ _ or j a z z (sample word) it will NOT swap between.
Aucun commentaire:
Enregistrer un commentaire