Problem with while [closed]

-3
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    BancoConta p1 = new BancoConta();
    p1.inicio();

}

public void inicio() {
    do {
        System.out.println("Para criar conta bancária: (1)");
        System.out.println("Para visualizar conta: (2)");
        escolha = sc.nextInt();
        System.out.println(escolha);
    } while (escolha!=1||escolha!=2);
    System.out.println("saiu");
}

You are not printing the "gone"

    
asked by anonymous 30.10.2017 / 19:05

1 answer

4

First, the escolha variable is not declared in this code.

But the big problem is that you used || instead of && . Look at this:

escolha!=1||escolha!=2

Consider, if escolha is 1, we have it is different from 2, so it remains in do-while . If it is 2, then it is different from 1 and also continues.

What you wanted was this:

escolha != 1 && escolha != 2
    
30.10.2017 / 19:13