0

this is basically the same thing i got to compare numbers from user input, with "int", but for some reason it doesnt work for words in an array of strings even when it is correct. its unfinished, i just want to make it compare properly.

            case 2:

            cell = (int)((Math.random() * 59) + 1);
            System.out.println(englishNumbers[cell]);
            System.out.println("what is the number? >");
            String w = in.nextLine();
            if(w != frenchNumbers[cell])
            {
                System.out.println("That is incorrect");
                numChoice(2);
            }
            else
            {
                System.out.println("That's correct");
                numChoice(2);
            }
            break;
  • i dont see how this is a duplicate from the given example. this is from user input not from 2 strings that are already defined. this compares input to one defined string array – Bilbro Swaggens Dec 27 '15 at 06:49

1 Answers1

0

Use if(!w.equals(frenchNumbers[cell]))

instead of

if(w != frenchNumbers[cell]).

You must compare values, not references.

Azat Nugusbayev
  • 1,391
  • 11
  • 19