Java - AND operator not working

前端 未结 4 1659
清歌不尽
清歌不尽 2021-01-27 12:27

newbie here,
I have two variables which generate random numbers through .Random. I want them keep rolling until both variables generate two different values, si

4条回答
  •  时光说笑
    2021-01-27 12:41

    the while execute the statement untill the condition is true. In your code the condition is given by (diceRolled1 != 5) && (diceRolled2 != 4). The && operator require true that all operands be true. Given this Your loop will end when at least one of the expression will be false.

    To finish the program when it generate 5 and 4 you have to use this:

    (!(diceRolled1 == 5) && (diceRolled2 == 4))

提交回复
热议问题