What's wrong with this while? O || it's not working [closed]

3
Scanner input = new Scanner(System.in);
String str = input.nextInt();
while ( (str.nextInt() != 5) || (str.nextInt() != 10) ){
    str = input.nextInt()
}

The code should invoke the nextInt() method every time the user types a number other than 5 or 10. What is happening here is that when I type 5 or 10 it keeps repeating, invoking the method nextInt() .

    
asked by anonymous 21.03.2016 / 19:06

2 answers

-1

What you need to understand is that you have three nextInt() commands in this snippet.

So the program can double nextInt() before entering ìf .

I understand by your explanation that you want to call nextInt() once , see if the return is 5 or 10, and only then call nextInt() a second time. Something like this:

bool continua = false;
do
{
    int primeiraLeitura = input.nextInt();
    if ( primeiraLeitura != 5 || primeiraLeitura != 10 )
    {
        int segundaLeitura int.NextInt();
        continua = true;
    }
} while (continua);
    
21.03.2016 / 19:54
-1
Scanner input = new Scanner(System.in);
String str = input.nextInt();
while ( str != 5) || str != 10) ){
    str = input.nextInt()
}
    
22.03.2016 / 02:10