[JAVA practice 2021.4.10]
An ordinary year that is divisible by 4 and not divisible by 100 is a leap year. (For example, 2004 is a leap year, and 1900 is not a leap year.)
A century year that is divisible by 400 is a leap year. (For example, 2000 is a leap year, but 1900 is not a leap year)
public static void main(String[] args)
Scanner sc=new Scanner(System.in);
System.out.println("请输入年份!");
int i=sc.nextInt();
if ((i%4==0)&&(i%100!=0)) {
System.out.println("闰年");
} else {
if (i%400==0) {
System.out.println("闰年");
} else {
System.out.println("不是闰年");
}
}
System.out.println(i);
System.out.println(10%100);
}
[Summary]
Combination of if judgments
- & The bitwise AND operator, the result is true only if both operands are true.
-
|| 位或运算符,只有两个操作数都是false,结果才是false。
-
&&:逻辑与运算,也是只有两个操作数都是true,结果才是true。但是如果左边 操作数为false,就不计算右边的表达式,直接得出false。类似于短路了右 边。
-
||:逻辑或运算,也是只有两个操作数都是false,结果才是false。但是如果左边操作数为true,就不计算右边的表达式,直接得出true。类似于短路了右边。
- !: Logical NOT operation, negates the operand.