【发布时间】:2011-12-13 18:20:39
【问题描述】:
抛出的异常是否表示数组大于索引?如果不是,那是什么意思,为什么?如何更正?
线程“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