求解!!新装eclipse运行一下代码报错 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ch4.SwitchDemo.main(SwitchDemo.java:20)
请各位大侠看一下代码
/**
*
*
*/
package ch4;
/**
* @author Administrator
*
*/
public class SwitchDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// get year,month
int year = Integer.parseInt(args[0]);
int month = Integer.parseInt(args[1]);
boolean flag = true; // declare is 'flag' the flag of leap year(闰年)
int days = -1; // declare the days of a month
// switch statement,
switch(month){
// when month is in 1,3,5,7,8,10,12, days are 31
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
// when month is in 4, 6, 9, 11, days are 30
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
// when month is February, is year leap year
case 2:
if((year%4==0&&year%100!=0)||(year%400==0)){ // is the year a leap year
flag = true;
days = 29;
}
else{ // year is not a leap year
flag = false;
days = 28;
}
}
if(flag){ // if year is a leap year, and then print year is leap year
System.out.println(year + "是闰年[is a leap year!]");
}
else{
System.out.println(year + "year不是闰年[is not a leap year!]");
}
System.out.println(year + "年" + "" + month + "月" + "" + days +"天!"); // print the year, month and days
}
}
谢谢各位大侠的真知灼见
------解决方案--------------------
认真看一下API文档,看入门书!