import java.text.DecimalFormat;
class Time3
{
private int hour;
private int minute;
private int second;
public void setTime(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
public void setHour(int h)
{
hour = ((h> =0 && h <24) ? h : 0);
}
public void setMinute(int m)
{
minute = ((m> =60 && m <60) ? m :0);
}
public void setSecond(int s)
{
second = ((s> =0 && s <60) ? s :0);
}
public int getHour (int h)
{
return hour;
}
public int getMinute(int m)
{
return minute;
}
public int getSecond(int s)
{
return second;
}
public String a()
{
DecimalFormat twoDigits = new DecimalFormat( "00 ");
return twoDigits.format(hour) + ": " +twoDigits.format(minute) + ": "+
twoDigits.format(second);
}
public String b()
{
DecimalFormat twoDigits = new DecimalFormat( "00 ");
return ((hour==12||hour==0) ? 12 : hour % 12) + ": " +twoDigits.format(minute)+ ": "+
twoDigits.format(second)+(hour <12 ? "AM " : "PM ");
}
public static void main(String[] args)
{
Time3 time = new Time3();
time.setTime(22,60,
60);
String w = time.b();
System.out.println(w);
}
}
我想将这个程序进行修改...
分别用三个方法使Time3对象所储存的时间分别增加1秒(当second > =60的时候minute就加1), 1分, 1小时
自己想了好久 却还是写不出来
请高手请教...
------解决方案--------------------
用SimpleDateFormat
让Calendar去实现你的要求,根本不用自己处理