这段代码有错误class Daemon extends Thread public void run() if(this.isDaemon()==false) System.our.println("thread is not daemon"): else System.out.println("thread is daemon") try for(int i=0;i<10;i++){ System.our.println() Threadsleep(200): catch (InterruptedException e)System.out.println("thread done!"); public class Test { public static void main (Stringll args)Thread t=new Daemon0); t.setDaemon(true) t.start0); try Thread.sleep(900); catch (InterruptedException e)System.out.println("main done!"):请给出改正后的代码
时间: 2024-02-15 21:04:57 浏览: 110
Win10 WSL运行docker报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
5星 · 资源好评率100%
以下是改正后的代码:
```
class Daemon extends Thread {
public void run() {
if (this.isDaemon() == false) {
System.out.println("Thread is not daemon.");
} else {
System.out.println("Thread is daemon.");
}
try {
for (int i = 0; i < 10; i++) {
System.out.println(i);
Thread.sleep(200);
}
} catch (InterruptedException e) {
System.out.println("Thread done!");
}
}
}
public class Test {
public static void main(String[] args) {
Thread t = new Daemon();
t.setDaemon(true);
t.start();
try {
Thread.sleep(900);
} catch (InterruptedException e) {
System.out.println("Main done!");
}
}
}
```
改正后的代码中,在“class Daemon extends Thread”后面添加了“{”,并在“public void run()”后面添加了“{”。同时,在if语句和else语句中添加了花括号“{ }”,并将“System.our”改为了“System.out”。在for循环中,“Threadsleep(200)”改为了“Thread.sleep(200)”并添加了花括号“{ }”。在catch语句中添加了花括号“{ }”。最后,在类定义和main方法定义后面添加了花括号“{ }”。
阅读全文