jeudi 31 janvier 2019

Program jumps into the if-statement no matter the the expression is

I have created a simple method. It bring a String of 1 char into the method. It then searches another string to see if that char is in the string. If it is not it returns an int index of -1. If int index is < 0 it moves on (which means there was not a match. If there is a match, it returns the index of the char (which would be 0 or higher). For some reason, no matter what it returns, it jumps in to that if-statement.

static void letterCheck(String guess) 
{


    String usedLetters = "abc";
    int index = usedLetters.indexOf(guess);
    System.out.println("\nYour letter is \"" + index + "\".");

    if (index >= 0);
    {
        System.out.println("\nYour index # is \"" + index + "\".");
        System.out.println("You have already guessed letter " + guess + " 
        before.");
        match(word, userGuess);;
    }


}

Aucun commentaire:

Enregistrer un commentaire