这个抛出的异常是否表示数组比索引大?如果不是,那么它表示什么,为什么会出现?我该如何纠正它?
在主线程中发生异常:"main" java.lang.ArrayIndexOutOfBoundsException: 0 在leapyear.LeapYear.main(LeapYear.java:13)
public class LeapYear {
public static void main(String[] args) {
int year = Integer.parseInt(args[0]);
boolean isLeapYear;
// divisible by 4
isLeapYear = (year % 4 == 0);
// divisible by 4 and not 100
isLeapYear = isLeapYear && (year % 100 != 0);
// divisible by 4 and not 100 unless divisible by 400
isLeapYear = isLeapYear || (year % 400 == 0);
System.out.println(isLeapYear);
}
}
System.out.println(args.length); // and order is restored
- user166390