So close....I get the proper output, but I have not fixed the runttime (apparently). I did fix the infinite loop I had it in (oops).
I have the countupIndex at 6 because It stops displaying at 4 if I set it to 5. I have a feeling that this is the line that I may have messed up but I'm not seeing the problem.
let me know if you see my error. and if I find it first I will mark this as solved.
package com.codegym.task.task16.task1626;
public class Solution {
public static int number = 5;
public static void main(String[] args) {
new Thread(new CountdownRunnable(), "Decrease").start();
new Thread(new CountUpRunnable(), "Increase").start();
}
public static class CountUpRunnable implements Runnable {
//write your code here
private int countupIndex = 1;
@Override
public void run() {
try{
while(true){
System.out.println(Thread.currentThread().getName()+": "+countupIndex);
countupIndex +=1;
if(countupIndex ==6) return;
Thread.sleep(500);
}
}catch (InterruptedException e){}
}
}
public static class CountdownRunnable implements Runnable {
private int countdownIndex = Solution.number;
public void run() {
try {
while (true) {
System.out.println(toString());
countdownIndex -= 1;
if (countdownIndex == 0) return;
Thread.sleep(500);
}
} catch (InterruptedException e) {
}
}
public String toString() {
return Thread.currentThread().getName() + ": " + countdownIndex;
}
}
}