?
package com.javarush.task.task16.task1617;
/*
Отсчет на гонках
*/
public class Solution {
public static volatile int numSeconds = 4;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
Thread.sleep(3500);
if (clock.isAlive()){
clock.interrupt();
} else{
System.out.print("Марш!");
}
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
int y = numSeconds;
try {
for (int i = 0; i < y; i++) {
System.out.print(numSeconds-- + " ");
RacingClock.sleep(1000);
}
} catch (InterruptedException e) {
System.out.print("Прервано!");
}
}
}
}