I can print the numbers 3, 2, 1 but no "Go!" and i can print 4, 3, 2, 1 "Interrupted!"... I am so pissed off!
package com.codegym.task.task16.task1617;
/*
Countdown at the races
*/
public class Solution {
public static volatile int numSeconds = 3;
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() {
try {
for (int i = numSeconds; i >= 1; i--) {
System.out.println(numSeconds + " ");
--numSeconds;
Thread.sleep(1000);
}
if (numSeconds == 3)
System.out.println(" Go!");
}
catch (InterruptedException e){
System.out.println(" Interrupted!");
}
}
}
}