Java 使用Thread类,模拟龟兔赛跑

Java 使用Thread类,模拟龟兔赛跑,第1张

Java 使用Thread类,模拟龟兔赛跑

使用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					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5583454.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存