vendredi 9 octobre 2015

Breaking a while loop with if statment - Java [duplicate]

This question already has an answer here:

This while loop is having some trouble breaking and I'm not quite sure what the problem is. If "S" is entered, the while loop still goes to the method and loops again. This should be an easy fix but I'm overlooking something here. Thanks in advanced!

String name;
    name = "a";
    while(name != "S")
    {
    System.out.println("Enter in the name of a business or enter S to exit");
    name = console.nextLine();
    if(name == "S"){
        break;}
    System.out.println(bSearch(name));
    }

Aucun commentaire:

Enregistrer un commentaire