急!!请教高手!!!
int ss=Integer.parseInt(args[0]);运行后有错误提示:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at eight.MyTime4.main(MyTime4.java:21)
代码附上:
public class Time3 {
private int hour;
private int minute;
private int second;
public Time3()
{setTime3(0,0,0);}
public Time3(int hh)
{setTime3(hh,0,0);}
public Time3(int hh,int mm)
{setTime3(hh,mm,0);}
public Time3(int hh,int mm,int ss)
{setTime3(hh,mm,ss);}
public void setTime3(int hh,int mm,int ss)
{setHour(hh);setMinute(mm);setSecond(ss);}
public void setHour(int hh)
{hour=((hh>=0&&hh<24)?hh:0);}
public void setMinute(int mm)
{minute=((mm>=0&&mm<60)?mm:0);}
public void setSecond(int ss)
{second=((ss>=0&&ss<60)?ss:0);}
public int gethour()
{return hour;}
public int getminute()
{return minute;}
public int getsecond()
{return second;}
public String toString()
{
return(hour+":"+(minute<10?"0":"")+minute+":"+(second<10?"0":"")+second);
}
}
public class MyTime4 {
private static Time3 t3;
public static void addSecond(int ss)
{
int sq=(t3.getsecond()+ss)/60;
int sr=(t3.getsecond()+ss)%60;
t3.setSecond(sr);
int mq=(t3.getminute()+sq)/60;
int mr=(t3.getminute()+sq)%60;
t3.setMinute(mr);
int hq=(t3.gethour()+mq)%24;
t3.setHour(hq);
}
public static void main(String args[])
{
t3=new Time3(3,33,33);
System.out.println("设置时间t3="+t3.toString());
int ss=Integer.parseInt(args[0]);
addSecond(ss);
System.out.println("修改后时间t3="+t3.toString());
}
}
[[it] 本帖最后由 当家的女人 于 2008-8-2 22:03 编辑 [/it]]