Help, please. What's wrong in my code?
Output in Idea is correct.
Input: numSeconds = 3. Output: 3 2 1 Go!
Input: numSeconds = 4. Output: 4 3 2 1 Interrupted!
package com.codegym.task.task16.task1617;
import java.util.ArrayList;
/*
Countdown at the races
*/
public class Solution {
public static volatile int numSeconds = 3;
public static String str = numSeconds + " ";
public static ArrayList<Integer> list = new ArrayList<>();
public static void finalPhrase() {
if (!list.contains(4)) {
System.out.println("Go!");
} else System.out.println("Interrupted!");
}
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
Thread.sleep(3500);
clock.interrupt();
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
System.out.print(str);
try {
while (numSeconds > 1) {
list.add(numSeconds);
numSeconds--;
Thread.sleep(1000);
System.out.print(numSeconds + " ");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
finalPhrase();
}
}
}