[java]代码库
package Clock;
public class Clock{
private int hour ;
private int minute ;
private int second ;
// private Display H = new Display(hour,24) ;
// private Display M = new Display(minute,60) ;
// private Display S = new Display(second,60) ;
public Clock(int hour , int minute , int second ) {
this.hour = hour ;
this.minute = minute ;
this.second = second ;
}
public void tick() {
Display S = new Display(second,60) ;
Display M = new Display(minute,60) ;
Display H = new Display(hour,24) ;
for(;;) {
S.increase() ;
this.second = S.getvalue() ;
if (S.getvalue() == 0) {
M.increase() ;
this.minute = M.getvalue() ;
if(M.getvalue() == 0) {
H.increase() ;
this.hour = H.getvalue() ;
}
}
}
}
public String toString() {
String res ;
String a1 = Integer.toString(hour) ;
String a2 = Integer.toString(minute) ;
String a3 = Integer.toString(second) ;
if (hour < 10) {
a1 = "0" + a1 ;
}
if (minute < 10){
a2 = "0" + a2 ;
}
if(second < 10) {
a3 = "0" + a3 ;
}
res = a1 + ":" + a2 + ":" + a3 ;
return res ;
}
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner(System.in);
Clock clock = new Clock(in.nextInt(),in.nextInt(),in.nextInt());
clock.tick();
System.out.print(clock);
in.close();
}
}