老师,作业有需要优化的吗

来源:2-8 自由编程

UUU加油

2022-05-15 17:05:42

public class Cat implements Runnable {

	@Override
	public void run() {
		for(int i=1;i<=3;i++) {
			System.out.println(Thread.currentThread().getName()+"A  Cat");
		}
		
	}

}
public class Dog implements Runnable {

	@Override
	public void run() {
		for(int i=1;i<=3;i++) {
			System.out.println(Thread.currentThread().getName()+"A  Dog");
		}

	}

}

public class AnimalTest {

	public static void main(String[] args) {
	    for(int i=1;i<=3;i++) {
	    	System.out.println("main thread");
	    }
		Cat cat=new Cat();
		Thread t1=new Thread(cat);
		t1.start();
		Dog dog=new Dog();
		Thread t2=new Thread(dog);
		t2.start();

	}

}


写回答

1回答

好帮手慕小尤

2022-05-15

同学你好,测试同学代码已完成练习,不需要优化,棒棒哒!

祝学习愉快!

0

0 学习 · 9886 问题

查看课程