package com.javarush.task.task16.task1617;

/*
Отсчет на гонках
*/

public class Solution {
    public static volatile int numSeconds = 5;

    public static void main(String[] args) throws InterruptedException {
        RacingClock clock = new RacingClock();
        //add your code here - добавь код тут

    }

    public static class RacingClock extends Thread {
        public RacingClock() {
            start();
        }

        public void run(){
            //add your code here - добавь код тут
            Thread t = new Thread();
            if (numSeconds < 3.5){
                for(int i = numSeconds; i>=0; i--){
                    if(numSeconds > 0) {
                        System.out.print(numSeconds + " ");
                        numSeconds--;
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            System.out.println(e);
                        }
                    }

                    else
                        System.out.println("Марш!");


                }
            }
            else{
                while(!(t.isInterrupted())){
                    if(numSeconds > 0) {
                        System.out.print(numSeconds + " ");
                        numSeconds--;
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            System.out.println(e);
                        }
                    }
                    else{

                        System.out.print("Прервано!");
                        try{
                            Thread.sleep(1000);}
                        catch (Exception e){
                            System.out.println(e);
                        }
                        t.interrupt();

                    }
                }
            }


    }
}}