if(numSeconds<4)
System.out.println("3 2 1 Go!");
else if(numSeconds>=4)
System.out.println("4 3 2 1 Interrupted!");
Thread.sleep(3500);
if ((float)numSeconds > 3.5) {
clock.interrupt();
}
}
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();
if(numSeconds<4)
System.out.println("3 2 1 Go!");
else if(numSeconds>=4)
System.out.println("4 3 2 1 Interrupted!");
Thread.sleep(3500);
if ((float)numSeconds > 3.5) {
clock.interrupt();
}
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
//write your code here
while(!isInterrupted()){
try{
numSeconds--;
Thread.sleep(1000);}
catch(InterruptedException e){
}
}
}
}
}