consider the following code:
static class ThreadTest extends Thread {
int x;
int[] y;
public ThreadTest(int x, int[] y) {
this.x = x;
this.y = y;
}
@Override
public void run() {
while (x< 10) {
++x;
System.out.print("0");
}
while (y[0] < 10) {
++y[0];
System.out.print('1');
}
}
}
public static void main(String args[]) {
int x = 0;
int[] y = new int[1];
y[0] = 0;
Thread A = new ThreadTest(x, y);
Thread B = new ThreadTest(x, y);
B.start();
A.start();
}
how many 1's and how many 0's will be printed? how can I ensure that the number of 1's will be the same every time the program runs? notice that the class is static
How is it possible to evaluate the max and min appearances of "1"?