千峰JAVA第29天作业

在千峰第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();
	}
}
发布了21 篇原创文章 · 获赞 0 · 访问量 1961

猜你喜欢

转载自blog.csdn.net/qq_40091389/article/details/104828977