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); clock.interrupt(); } public static class RacingClock extends Thread { public RacingClock() { start(); } public void run() { String s = ""; if(numSeconds==3) { for(int i = numSeconds; i>0; i--) { s = numSeconds + " "; numSeconds--; System.out.print(s); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.print("Марш!"); e.printStackTrace(); } } } if (numSeconds == 4) { for(int i = numSeconds; i>0; i--) { s = numSeconds + " "; numSeconds--; System.out.print(s); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.print("Прервано!"); e.printStackTrace(); } } } } } }