public class LeapYear {
public static void main(String args[]) {
int year =1989; //方法1
if(year%4==0&&year%100!=0)||(year%400==0)
System.out.println(year+"是闰年");
else System.out.println(year+"不是闰年");
}
}
错误提示是Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "||", if expected
at Test/hello.LeapYear.main(LeapYear.java:6)
public static void main(String args[]) {
int year = 1989; //方法1
if ((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0))
System.out.println(year + "是闰年");
else System.out.println(year + "不是闰年");
}
需要在if的条件前后再加上一层括号
楼上说的对。if用于判断条件,对判断的条件加上一层括号
if少了个最外层的括号哦