我不确定为什么会出现错误,该错误一直表示存在非法表达的错误并且')'是预期的错误。它发生在第14行。
1 import java.io.*;
2 public class LeapYear{
3 public static void main(String[] args){
4 String leapYear="";
5 int intleapYear;
6
7 BufferedReader input = new BufferedReader(
8 new InputStreamReader(System.in));
9
10 try{
11 System.out.print("Enter a year: " +leapYear);
12 leapYear=input.readLine();
13 intleapYear=Integer.parseInt(leapYear);
14 boolean isleapyear= ((intleapYear%4==0)&&(intleapYear%100!==0)||(intleapYear%400==0));
16
17
18 if(isleapyear){
19 System.out.println(intleapYear + " is a leap year.");
20 } else
21 System.out.println(intleapYear + " is not a leap year.");
22
23 }catch(IOException e){
24 System.out.println("Error");
25 }
26
27
28
29
30 /*if ((intleapYear%4==0)&&(intleapYear%100!==0)||(intleapYear%400==0)){
31 System.out.println(intleapYear+" is a leap year.");
32 }else
33 System.out.println(intleapYear+" is not a leap year.");*/
}
}
答案 0 :(得分:0)
这是因为您使用的是!==
你应该使用!=
所以第14行将是:
boolean isleapyear= ((intleapYear%4==0)&&(intleapYear%100!=0)||(intleapYear%400==0));