【发布时间】:2016-03-16 23:21:07
【问题描述】:
我刚开始使用 Java,我正在玩我在网上复制的代码。我在网上复制了这段代码并尝试在eclipse上运行它
http://introcs.cs.princeton.edu/java/12types/SpringSeason.java.html
public class SpringSeason {
public static void main(String[] args) {
int month = Integer.parseInt(args[0]);
int day = Integer.parseInt(args[1]);
boolean isSpring = (month == 3 && day >= 20 && day <= 31)
|| (month == 4 && day >= 1 && day <= 30)
|| (month == 5 && day >= 1 && day <= 31)
|| (month == 6 && day >= 1 && day <= 20);
System.out.println(isSpring);
}
}
我在 Eclipse 上不断收到此错误
线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 0 在 trollstartwo.main(trollstartwo.java:4)
【问题讨论】:
-
运行时需要传递2个参数,例如
java SpringSeason 3 16 -
你如何调用你的程序?它期望在命令行上传递两个参数:
java SpringSeason 3 20。 -
请注意,这在链接文件的顶部进行了描述。
-
你的标题让我不寒而栗……