Тема: Не зрозуміла частина коду.
// Поясніть будь ласка як тут працює ось цей цикл
//while (ivanov.getCountSpeeches() + petrov.getCountSpeeches()
// + sidorov.getCountSpeeches() < totalCountSpeeches) {
// }
//
public class Solution {
public static int totalCountSpeeches = 200;
public static int soundsInOneSpeech = 1000000;
public static void main(String[] args) throws InterruptedException {
Politician ivanov = new Politician("Іван");
ivanov.join();
Politician petrov = new Politician("Петро");
Politician sidorov = new Politician("Сидор");
while (ivanov.getCountSpeeches() + petrov.getCountSpeeches()
+ sidorov.getCountSpeeches() < totalCountSpeeches) {
}
System.out.println(ivanov);
System.out.println(petrov);
System.out.println(sidorov);
}
public static class Politician extends Thread {
private volatile int countSounds;
public Politician(String name) {
super(name);
start();
}
public void run() {
while (countSounds < totalCountSpeeches * soundsInOneSpeech) {
countSounds++;
}
}
public int getCountSpeeches() {
return countSounds / soundsInOneSpeech;
}
@Override
public String toString() {
return String.format("%s сказав слово %d разів", getName(), getCountSpeeches());
}
}
}