Java - AND operator not working

前端 未结 4 1715
清歌不尽
清歌不尽 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:53

    Yeah,it should be. The program should end if dicerolled is either 5 or 4 because as far as it is not 4 and not 5 it is in while loop. It exits the while loop if only the value is either 4 or 5. So your logic is incorrect. Sorry! :) Try:

    while (!(dicerolled ==4 && dicerolled == 5))
    

提交回复
热议问题