I see "3 3 2 1 Start!"
package pl.codegym.task.task16.task1617;
/*
Odliczanie na wyścigach
*/
public class Solution {
public static volatile int numSeconds = 3;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
//tutaj wpisz swój kod
Thread clockThread = new Thread(clock);
clock.start();
Thread.sleep(3500);
clock.interrupt();
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
//tutaj wpisz swój kod
String s = "";
Thread current = Thread.currentThread();
if (numSeconds < 4) {
s = "Start!";
while (numSeconds > 0) {
try {
System.out.print(numSeconds + " ");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
--numSeconds;
}
System.out.println(s);
} else if (numSeconds >= 4) {
s = "Przerwany!";
while (numSeconds > 0) {
System.out.print(numSeconds + " ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
numSeconds--;
if (numSeconds == 0) {
//System.out.println("Przerwany!");
current.interrupt();
}
}
}
}
}
}