求龟兔赛跑Java代码
import java.applet;import java.awt;class RunningAnimal extends Thread {int distance;int speed;int sleeptime;int length;List list;String name;public void run() {while (distance < length){distance+=speed;sleep(sleeptime);catch (InterruptedException e) {list.addItem(name+":"+distance);list.addItem(name+" arrives.");RunningAnimal(String aname,int alldistance,int aspeed,int asleeptime,List alist)name=aname;length=alldistance;speed=aspeed;sleeptime=asleeptime;distance=0;list=alist;public class TestThread extends Applet {RunningAnimal turtle;RunningAnimal rabit;public void init() {setLayout(new BorderLayout());List lList=new List();add("Center",lList);turtle=new RunningAnimal("Turtle",500,20,20,lList);turtle.setPriority(7);turtle.start();rabit=new RunningAnimal("Rabit",500,300,500,lList);rabit.setPriority(3);rabit.start();很炫的标题,顶一个!爱死你啊啊啊啊啊 空军司令风格
c++龟兔赛跑问题,在线等,急!!!!
#include
usingnamespacestd;
intmain()
intv_rabbit=9;//兔子速度
intv_Turtle=3;//乌龟速度
intt=40*60;//40分钟
ints_rabbit=0;
ints_Turtle=0;
intt_rabbit=1;//兔子跑的时间
intt_sleep=0;
boolb_sleep=false;
intt_back=1;//回头时间
for(inti=0;i
s_Turtle=v_Turtle*(i+1);//乌龟跑的路程
s_rabbit=t_rabbit*v_rabbit;//兔子跑得路程
if(b_sleep)
++t_sleep;
if(t_sleep==30*60)//睡半个小时
b_sleep=false;
elseif(s_rabbit>s_Turtle&&!b_sleep&&(t_back==10*60))//没睡觉时兔子检查是否超过乌龟
b_sleep=true;
t_back=1;
elseif(!b_sleep)//没睡觉时兔子跑路
t_rabbit++;
t_back++;
cout<<"s_Turtle:"<
cout<<"s_rabbit:"<
return0;
用英语编写“龟兔赛跑”的故事
求java龟兔赛跑程序代码!
import java.applet;import java.awt;class runninganimal extends thread {int distance;int speed;int sleeptime;int length;list list;string name;public void run() {while (distance < length){distance+=speed;try {sleep(sleeptime);}catch (interruptedexception e) {}list.additem(name+":"+distance);}list.additem(name+" arrives.");}runninganimal(string aname,int alldistance,int aspeed,int asleeptime,list alist){name=aname;length=alldistance;speed=aspeed;sleeptime=asleeptime;distance=0;list=alist;}}public class testthread extends applet {runninganimal turtle;runninganimal rabit;public void init() {setlayout(new borderlayout());list llist=new list();add("center",llist);turtle=new runninganimal("turtle",500,20,20,llist);turtle.setpriority(7);turtle.start();rabit=new runninganimal("rabit",500,300,500,llist);rabit.setpriority(3);rabit.start();}}