public class TestThread1 { int i,j; TestThread1(){ i=0; j=0; }public void go(int flag){ while(true){ try{ Thread.sleep(100); }catch(InterruptedException e){ System.out.println("Interrupted"); } if(flag==0){ i++; System.out.println("i=" + i); }else{ j++; System.out.println("j=" + j); } }//end of while }//end of go public static void main(String[] args) { new TestThread1().go(0); new TestThread1().go(1); }} 我已经给你调试了,完全通过,可以运行。
你最好用Eclipse3.0这样的集成开发工具,那些非逻辑性的错误它会提示你并给出修改方案。
{
int i,j; TestThread1(){
i=0;
j=0;
}public void go(int flag){
while(true){ try{ Thread.sleep(100);
}catch(InterruptedException e){
System.out.println("Interrupted");
} if(flag==0){
i++;
System.out.println("i=" + i);
}else{
j++;
System.out.println("j=" + j);
} }//end of while
}//end of go
public static void main(String[] args)
{
new TestThread1().go(0);
new TestThread1().go(1);
}}
我已经给你调试了,完全通过,可以运行。
2、程序里有太多的“全角空格”
{
int i,j;
TestThread1(){
i=0;
j=0;
}public void go(int flag){
while(true){try{ Thread.sleep(100);
}
catch(InterruptedException e){
System.out.println("Interrupted");
}if(flag==0){ i++;
System.out.println("i=" + i);
}
else{
j++;
System.out.println("j=" + j);
}
}//end of while
}//end of go
public static void main(String[] args)
{
new TestThread1().go(0);
new TestThread1().go(1);
}}
可以通过了
你的这个TestThread1(){i=0,j=0;}
JAVA中有这样的写法吗?
illegal character: \12288 ==>转成十六进制\u3000
也就是:
char c = '\u3000'; //全角空格
问题总算解决了,原来是这样的,上面的程序是我在一个网页上直接复制过来的,后来经沙虫兄和流星兄的指点,发现程序中有中文空格,看不到的哦!所以无论我怎么检查,也没有发现是这样的错误!所以,各位兄弟你们在网上看到好的程序,直接复制过来时,可要注意此问题哦!真不好意思,我没有太多的分了,这个问题我只有五分送出,不好意思哦,我想分数不是最重要的,我们共同进步才是最重要的,是吗?
祝你成功,也让CSDN成为我们共同热爱的家园!