在千峰第29天
“金石为开”
中国加油,武汉加油,千峰加油,我自己加油。
Q12
8、
AC
9
class MyThread1 implements Runnable {
public void run(){
for(int i=0;i<100;i++){
this.sleep((int)(Math.random()*1000));
System.out.println("hello");}}
private void sleep(int i) {
}
}
class MyThread2 extends Thread{
public void run(){
for(int i=0;i<100;i++){
try {
this.sleep((int)(Math.random()*1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("world");}}}
public class Homework8{
public static void main(String args[]){
Runnable t1=new MyThread1();
Thread t2=new MyThread2();
Thread T1 = new Thread(t1);
T1.start();
t2.start();
}
}