我是一个java初学者,我试着让下面的代码工作。为什么在解析args []数组时遇到ArrayIndexOutOfBoundsException?
class AgeCalc {
public static void main (String args[]) {
int yob = Integer.parseInt(args[1]);
int current = Integer.parseInt(args[0]);
int age = current - yob;
boolean hadBday = Boolean.parseBoolean(args[2]);
if (hadBday) {
System.out.println("You've already had your birthday");
} else {
age--;
System.out.println ("You've not had your birthday");
}
System.out.println("You are " + age + " years old!");
}
}
我得到的错误是:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at AgeCalc.main(AgeCalc.java:5)
你传递给程序的参数是什么? – David
请链接到本教程。 –
的可能的复制[java.lang.ArrayIndexOutOfBoundsException:0](http://stackoverflow.com/questions/23456742/java-lang-arrayindexoutofboundsexception-0) – Tom