Multiple conditions in a while loop

霸气de小男生 提交于 2019-12-02 08:03:32

It should be

while( !(cal.get(Calendar.YEAR) == 2001 && cal.get(Calendar.MONTH) == 0 && cal.get(Calendar.DAY_OF_MONTH) == 1) ) { // while not 1/1/2001

This is just a simple logic error. If even one of those is false (say, if the month IS 0), then you have true && false && true, which is false.

You need the "not" outside of the entire expression, or you need to use "||" to combine them:

while( !(year == 2001 && month == 0 && day == 1) )

or

while( (year != 2011) || (month != 0) || (day != 1) )
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!