0

Here is the code giving me trouble:

    String more = "yes";
    Scanner in = new Scanner(System.in);

    while (more != "no") {
            //do stuff          
            System.out.println("Want to add more? (yes or no)");
            more = in.nextLine();
    }

So long as the user does not enter "no," the loop should continue. The issue is that when I enter no, it still doesn't stop.

Terri
  • 1
  • 1
  • 1
  • 2
  • use while(!more.equals("no")) – GammaOmega Oct 18 '15 at 18:22
  • You can't compare 2 strings with `==` this is only used for comparing values of simple types `int, char, double...` or references of objects. Now, in your case you'll need to use : `while (!more.equals ("no"))` –  Oct 18 '15 at 18:27
  • Works like a charm. Thank you! – Terri Oct 18 '15 at 18:40

0 Answers0