Не пойму как с помощью объекта уменьшить значение переменной numSeconds на 1. Зачем это вообще нужно? Вроде работает.
package com.javarush.task.task16.task1617;
/*
Отсчет на гонках
*/
public class Solution {
public static volatile int numSeconds = 4;
public static boolean stop = true;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
clock.start();
try {
Thread.sleep(3500);
clock.interrupt();
}
catch (InterruptedException e)
{
}
}
public static class RacingClock extends Thread {
public RacingClock() {
}
public void run() {
try {
while (true) {
System.out.print(numSeconds + " ");
Thread.sleep(1000);
if (numSeconds == 1) {
System.out.println("Марш!");
break;
}
numSeconds -= 1;
}
} catch (InterruptedException e) {
System.out.println("Прервано!");
}
}
}
}
Тоже не прокатило.