Java题问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 04:22:37
class num implements Runnable
{
int money;
Thread one,two;
public num
{
Thread one = new Thread();

Thread two = new Thread();

}
public void getMoney(int n)
{
this.money=n;
}
while(true)
{
money = money-50;
if(Thread.currentThread()==one)
{
System.out.println("money");
}
if(money<=150)
{
System.out.println("线程ONE死亡");
return;
}
if(Thread.currentThread()==two)
{
System.out.println("钱"+money);
}
if(money<=0)
{
System.out.println("two死亡");
return;
}

}
}
public class kij
{
public static void main(String ages[])
{
num h = new num();
h.getMoney(300);
h.one.start();
h.two.start();
}
}
问一下, 这段代码里面哪里出错了。
希望大家帮忙看一下。

class num implements Runnable
{
int money;
Thread one,two;
num()
{
one = new Thread(this);

two = new Thread(this);
}
public void getMoney(int n)
{
this.money=n;

}
public void run(){
while(true)
{
money = money-50;
if(Thread.currentThread()==one)
{
System.out.println("money");
}
if(money<=150)
{
System.out.println("线程ONE死亡");
return;
}
if(Thread.currentThread()==two)
{
System.out.println("钱"+money);
}
if(money<=0)
{
System.out.println("two死亡");
return;
}
}
}
}
public class kij
{
public static void main(String[] agrs)
{
num h = new num();
h.getMoney(30000);
h.one.start();
h.two.start();
}
}

说实话 我不知道你这个程序的意图