[Java] 时钟 →→→→→进入此内容的聊天室

来自 , 2020-12-01, 写在 Java, 查看 132 次.
URL http://www.code666.cn/view/231141b3
  1. package Clock;
  2. public class Clock{
  3.    private int hour ;
  4.    private int minute ;
  5.    private int second ;
  6.    
  7. // private Display H = new Display(hour,24) ;
  8. // private Display M = new Display(minute,60) ;
  9. // private Display S = new Display(second,60) ;
  10.    
  11.    public Clock(int hour , int minute , int second ) {
  12.        this.hour = hour ;
  13.        this.minute = minute ;
  14.        this.second = second ;
  15.    }
  16.    public void tick() {
  17.         Display S = new Display(second,60) ;
  18.         Display M = new Display(minute,60) ;
  19.         Display H = new Display(hour,24) ;
  20.         for(;;) {
  21.         S.increase() ;
  22.         this.second = S.getvalue() ;
  23.         if (S.getvalue() == 0) {
  24.              M.increase() ;
  25.              this.minute = M.getvalue() ;
  26.              if(M.getvalue() == 0) {
  27.                  H.increase() ;
  28.                  this.hour = H.getvalue() ;
  29.              }
  30.           }
  31.         }
  32.    }
  33.  
  34.    public String toString() {
  35.        String res ;
  36.        String a1 = Integer.toString(hour) ;
  37.        String a2 = Integer.toString(minute) ;
  38.        String a3 = Integer.toString(second) ;
  39.        if (hour < 10) {
  40.            a1  = "0" + a1 ;
  41.        }
  42.        if (minute < 10){
  43.            a2  = "0" + a2 ;
  44.        }
  45.        if(second < 10) {
  46.            a3  = "0" + a3 ;
  47.        }
  48.        res = a1 + ":" + a2 + ":" + a3 ;
  49.        return res ;
  50.    }
  51.    
  52.  
  53. public static void main(String[] args) {
  54.          
  55.          
  56.     java.util.Scanner in = new java.util.Scanner(System.in);
  57.  
  58.     Clock clock = new Clock(in.nextInt(),in.nextInt(),in.nextInt());
  59.  
  60.     clock.tick();
  61.  
  62.     System.out.print(clock);
  63.  
  64.     in.close();
  65.  
  66. }
  67. }
  68.  

回复 "时钟"

这儿你可以回复上面这条便签

captcha