0

Accessing the loop update from other class

Hi, I'm able to access a variable from another class in my code. What I want next is to access the while loop update and print or use the results on another class. I used threading because the two methods must perform action at a same time. Please see my code. https://code.sololearn.com/cFGMfBUfS7oR/?ref=app

3rd Jan 2022, 4:54 PM
Sibusiso Mbambo
3 ответов
0
What is your expected output?
4th Jan 2022, 11:32 AM
Jayakrishna 🇮🇳
0
Expected output is on the if statement ==> if(counterB == 3){ System.out.println("Access " + result);}
4th Jan 2022, 4:19 PM
Sibusiso Mbambo
0
here counter is running and the other class (thread main) is reading the status. Run it more times for different result class Counter extends Thread { int value, maxValue=30; public void run() { while(value < maxValue) { value++; System.out.println("counter is " +value); } } } public class ReadCounter { public static void main(String[] args) { Counter counter = new Counter(); counter.start(); for (int access=0; access++ < 15;) { System.out.println( "got " +counter.value ); } } }
4th Jan 2022, 9:01 PM
zemiak