题目这个运气一秒我无法理解,希望大家可以帮帮我
package zh.codegym.task.task16.task1613;
/*
大本钟
*/
public class Solution {
public static volatile boolean isStopped = false;
public static void main(String[] args) throws InterruptedException {
Clock clock = new Clock("伦敦", 23, 59, 57);
Thread.sleep(500);
isStopped = true;
Thread.sleep(500);
}
public static class Clock extends Thread {
private String cityName;
private int hours;
private int minutes;
private int seconds;
public Clock(String cityName, int hours, int minutes, int seconds) {
this.cityName = cityName;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
start();
}
public void run() {
try {
while (!isStopped) {
printTime();
}
} catch (InterruptedException ignored) {
}
}
private void printTime() throws InterruptedException {
//在此编写你的代码
if(seconds<60)
seconds++;
if(seconds==60 && minutes<60)
{minutes++;seconds=0;}
if(minutes==60 && hours<24)
{hours++;minutes=0;}
if(hours==24 )
{
hours=0;
minutes=0;
seconds=0;
}
if (hours == 0 && minutes == 0 && seconds == 0) {
System.out.println(String.format("当前是%s的午夜!", cityName));
} else {
System.out.println(String.format("在%s,时间现在是 %02d:%02d:%02d!", cityName, hours, minutes, seconds));
}
}
}
}