Please help don`t understand why it`s not working. When i tested the code with 3 in my Inteliji it worked just fine. With 4 im not sure if I´m getting the supposed result.
package com.codegym.task.task16.task1617;
/*
Countdown at the races
*/
public class Solution {
public static volatile int numSeconds = 4;
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() {
int count = numSeconds;
while(!Thread.currentThread().isInterrupted()) {
try {
System.out.print(count + " ");
Thread.sleep(1000);
count--;
if(count== 0) {
break;
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
if(numSeconds == 3) {
System.out.print("Go!");
}
else if (numSeconds == 4) {
System.out.print("Interrupted!");
}
}
}
}