我是一個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