public class Solution { public static volatile int countSeconds = 3; public static void main(String[] args) throws InterruptedException { RacingClock clock = new RacingClock(); Thread.sleep(3500); if (clock.isAlive()) clock.interrupt(); } public static class RacingClock extends Thread { public RacingClock() { start(); } public void run() { try{ while (this.isInterrupted()) { System.out.print(countSeconds + " "); Thread.sleep(1000); countSeconds--; if(countSeconds == 0){ System.out.println("Марш!"); return; } } }catch (InterruptedException e) { System.out.println("Прервано!"); } } } }