使用Thread类,模拟龟兔赛跑
package test1;
public class test1 extends Thread
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Thread Rabbit = new Thread (new test1 ("rabbit",15,50));
Thread Turtle = new Thread (new test1 ("turtle",12,50));
Turtle.start();
Rabbit.start();
System.out.println("This is the main application.");
}
String name;
int speed;
int distance;
int curdistance;
public test1 (String name,int speed,int distance)
{
this.name = name;
this.speed = speed;
this.distance = distance;
}
public void run()
{
while(curdistance