class Play {
public static void main(String[] args){
Window w = new Window();
new Thread(w,"线程1").start();
new Thread(w,"线程2").start();
}
}
class Window implements Runnable {
int[] a =new int[6];int i=0;
public void run(){
while (i<6) {
Thread t = Thread.currentThread();
a[i]=(int)(100*Math.random())+1;
System.out.println(t.getName() +"往数组里存入了"+ a[i] );
i++;
try {
t.sleep(1000);
}
catch (InterruptedException e) {
e.getStackTrace();
}
}
for (int i =0;i<=5 ;i++ ) {
System.out.print(a[i]+" ");
}
}
}
为什么输出的时候会有6个0?
而且随机产生的前两个数,,总是一样的
|
|