vendredi 29 mai 2015

Program does not enter if statement

So I have a mistake detection program that should detect a "mistake" if the current word (String cWrd) is not contained in a static array (passed as a parameter). If the word is not found in the array, "boolean found" remains false and a JLabel is set to "wrong category" for some period of time. However, the method does not appear to execute even when cWrd is not contained within the array.

CODE:

//Mistake method

public void mistake(String[] arr)

{
        int i = 0;
        boolean found = false;
        while (i < arr.length && found == false)
        {
            if (arr[i].equals(cWrd))
            {
                found = true;
            }
            i++;
        }
        if (found = false)     //The program never enters this if statement
        {
        lmid.setText("Wrong Category!");
        try {
            t1.sleep(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }


}

Aucun commentaire:

Enregistrer un commentaire