while循环中的多个条件

Ger*_*ley 1 java while-loop

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CountingSundays {

    public static void main(String args[]) {

        Calendar cal = new GregorianCalendar(1901, 00, 01); // month set to 0for jan , 1= feb etc

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

                System.out.print(cal.get(Calendar.MONTH));
            // cal.add(Calendar.DAY_OF_MONTH, 1);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图通过一次添加一天迭代while循环,但它甚至不会第一次访问while循环.while循环中的条件是否正确?当我测试它时,它只使用一个条件,但当我添加第二个条件时停止.

Axe*_*xel 5

它应该是

while( !(cal.get(Calendar.YEAR) == 2001 && cal.get(Calendar.MONTH) == 0 && cal.get(Calendar.DAY_OF_MONTH) == 1) ) { // while not 1/1/2001
Run Code Online (Sandbox Code Playgroud)