In my tests is OK, but I have two errors in Requirements.
package pl.codegym.task.task16.task1617;
/*
Odliczanie na wyścigach
*/
public class Solution {
public static volatile int numSeconds = 4;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
Thread.sleep(3500);
if (clock.isAlive()) {
clock.interrupt();
clock.stop();
System.out.println("Przerwany!");
}
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
while (numSeconds > 0) {
System.out.printf(numSeconds-- + " ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Start!");
interrupt();
}
}
}