一道JAVA程序设计题,高手帮忙,谢了

根据以下要求编写一个时间类Time,要求:
①该类有hour、minute、second三个私有整型成员变量(分别代表时、分、秒)。
②定义构造方法Time(int h,int m,int s)。
③定义public String toString()方法,以时:分:秒形式返回表示时刻的字符串。

public class TimerTest {
public static void main(String[] args) {
Time time=new Time(12,00,00);
System.out.print(time.toString());
}

}
/**
* 根据以下要求编写一个时间类Time,要求:
* ①该类有hour、minute、second三个私有整型成员变量(分别代表时、分、秒)。
* ②定义构造方法Time(int h,int m,int s)。
* ③定义public String toString()方法,以时:分:秒形式返回表示时刻的字符串。
*/
class Time{
private int hour,minute,second;
public Time(int h,int m,int s){
this.hour=h;
this.minute=m;
this.second=s;
}
public String toString(){
return this.hour+":"+this.minute+":"+this.second;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-03-06
被楼上的抢先了,可惜了
第2个回答  2010-03-06
我靠,这种题目也干拿出来
相似回答