Java do-while loop isn't working

后端 未结 3 1250
一个人的身影
一个人的身影 2021-01-26 02:31

I want my program to keep asking the question until it gets a response it can use, specifically a number from 0 to 20. I have a lot of other stuff on this class, so here is a sm

3条回答
  •  没有蜡笔的小新
    2021-01-26 03:05

    while(work = false); // here you are assigning false to work
    

    should be

    while(work == false); //here you are checking if work is equal to false
    
    • = an assignment operator used to assign value
    • == an equality operator used to check if two operands have same value.

    As work is boolean you could even just use this:

    while(!work)
    

提交回复
热议问题