本帖最后由 回首、后_街 于 2013-5-11 14:06 编辑
public static void DateTime(Calendar c){
String[] str = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
String[] str1={"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int index = c.get(Calendar.MONDAY);
int index1 =c.get(Calendar.DAY_OF_MONTH);
System.out.println(c.get(Calendar.YEAR)+"年");
System.out.println(str[index]);
System.out.println(c.get(Calendar.DAY_OF_MONTH)+"日");
System.out.println(str1[index1]);
}
public static void main(String[] ages){
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, 1);
DateTime(c);
}
该程序运行后爆出数组越界 是什么原因导致的呢????
运行结果
2013年
五月
12日
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
at Test.DateTime(Test.java:52)
at Test.main(Test.java:26)
|
|