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;
}
}
温馨提示:答案为网友推荐,仅供参考