模拟龟兔赛跑
线程1
package test;
/**
* 模拟龟兔赛跑
* @author Administrator
*
*/
class Rab extends Thread{
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("兔子跑了"+i+"步");
}
}
}
class array1 extends Thread{
public void run() {
for (int i = 0; i < 100; i++) {
i++;
System.out.println("乌龟跑了"+i+"步");
}
}
}
主类
package test;
public class Rabbit {
public static void main(String[] args) {
array1 rab=new array1();
Rab tor=new Rab();
rab.start();
tor.start();
}
}
![运行后的图片](https://img-blog.csdnimg.cn/20190324222453428.png)