居然有错?

来源:百度知道 编辑:UC知道 时间:2024/06/14 16:06:10
public class A{
Thread t1=new Thread();
int a=5;
boolean m=true;
public void run(){
whlie(m){
a=a+5;
System.out.println("怪物A"+a);
}
}
class B{
Thread t2=new Thread();
int b;
boolean n=true;
public void run(){
whlie(n){
b=b+5;
System.out.println("怪物"+b);
}
}
}
public static void main(String[] args){
int c=a-b;
whlie(c<0){
t1.start();
t2.start();
}
System.out.printn(c);
}
}

实在是看不懂你的代码,问题太多了。
首先,语句拼写错误 while写成whlie、System.out.println写成System.out.printn
其次,静态方法中访问非静态变量,例如:main方法中的a, b, t1, t2

凭着自己感觉改一下吧,不知道是不是你想要的答案:
public class A {

static int a = 5;
static boolean m = true;
static Thread t1 = new Thread() {
public void run() {
while (m) {
a += 5;
System.out.println("怪物A" + a);
}
}
};

static class B {
static int b = 0;
static boolean n = true;
static Thread t2 = new Thread() {
public void run() {
while (n) {
b += 5;
System.out.println("怪物" + b);
}
}

};
}

public static void main(String[] args){
int c = a - B.b;
while(c <= 0) {
t1.start();
B.t2.start();
}
System.out.println(c);
}
}
另外,你的条件是死循环,程序永远无法结束