当我用命令行输入2009 33(33是月)后应该出现异常,但异常后为什么还有部分代码能运行?
import java.util.Calendar;
import java.util.GregorianCalendar;
class GetForm
{
int year,month;
GetForm(int yeartemp,int monthtemp)
{
year=yeartemp;
month=monthtemp;
}
String getMonth()
{
String m[]={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
return m[month];
}
int getDate()
{
int d[]={31,28,31,30,31,30,31,31,30,31,30,31};
return d[month];
}
void printForm()
{
int monthfirstday;
int date;
GregorianCalendar objG=new GregorianCalendar(year,month,1);
try
{
String printmonth=getMonth();
System.out.println("\t\t\t"+year+"年"+printmonth);
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("超出范围");
}
monthfirstday=objG.get(Calendar.DAY_OF_WEEK)-1;
System.out.println("\t日\t一\t二\t三\t四\t五\t六");
date=getDate();
if(objG.isLeapYear(objG.get(Calendar.YEAR))&&month==1)
date++;
for(int i=0;i<monthfirstday;i++)
{
System.out.print("\t");
}
for(int i=1;i<date;i++)
{
if(i<=9)
System.out.print(" ");
System.out.print("\t"+i);
if((monthfirstday+i)%7==0)
{
System.out.println();
}
else
System.out.print(" ");
}
}
}
public class PrintDate
{
PrintDate()
{}
public static void main(String args[])
{
int year=0,month=0;
if(args.length==2)
{
try
{
year=Integer.parseInt(args[0]);
month=Integer.parseInt(args[1])-1;
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("未给出参数");
}
catch(NumberFormatException ne)
{
System.out.println("不是一个数");
return;
}
}
else
{
Calendar objC=Calendar.getInstance();
year=objC.get(Calendar.YEAR);
month=objC.get(Calendar.MONTH);
}
GetForm obj=new GetForm(year,month);
obj.printForm();
}
}
import java.util.Calendar;
import java.util.GregorianCalendar;
class GetForm
{
int year,month;
GetForm(int yeartemp,int monthtemp)
{
year=yeartemp;
month=monthtemp;
}
String getMonth()
{
String m[]={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
return m[month];
}
int getDate()
{
int d[]={31,28,31,30,31,30,31,31,30,31,30,31};
return d[month];
}
void printForm()
{
int monthfirstday;
int date;
GregorianCalendar objG=new GregorianCalendar(year,month,1);
try
{
String printmonth=getMonth();
System.out.println("\t\t\t"+year+"年"+printmonth);
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("超出范围");
}
monthfirstday=objG.get(Calendar.DAY_OF_WEEK)-1;
System.out.println("\t日\t一\t二\t三\t四\t五\t六");
date=getDate();
if(objG.isLeapYear(objG.get(Calendar.YEAR))&&month==1)
date++;
for(int i=0;i<monthfirstday;i++)
{
System.out.print("\t");
}
for(int i=1;i<date;i++)
{
if(i<=9)
System.out.print(" ");
System.out.print("\t"+i);
if((monthfirstday+i)%7==0)
{
System.out.println();
}
else
System.out.print(" ");
}
}
}
public class PrintDate
{
PrintDate()
{}
public static void main(String args[])
{
int year=0,month=0;
if(args.length==2)
{
try
{
year=Integer.parseInt(args[0]);
month=Integer.parseInt(args[1])-1;
}
catch(ArrayIndexOutOfBoundsException ae)
{
System.out.println("未给出参数");
}
catch(NumberFormatException ne)
{
System.out.println("不是一个数");
return;
}
}
else
{
Calendar objC=Calendar.getInstance();
year=objC.get(Calendar.YEAR);
month=objC.get(Calendar.MONTH);
}
GetForm obj=new GetForm(year,month);
obj.printForm();
}
}
解决方案 »
- 上转型对象的 过程
- 问一个JDialog的问题
- JLabel拖动问题
- (急)linux oracle jdbc
- java连接数据库的问题,闷啊,Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- java有没有能实现定时功能的包?
- 多边形
- 新手在干中学习JAVA,第一步,文本编辑器!
- java和oracle的问题?
- jbuilder中开发EntityBean
- HashMap的警告信息
- 在一句混合字符串里面可能存在多个英文句号“.”,如何匹配适当位置的那个句号?
date = getDate();//throw ArrayIndexOutOfBoundsException