我收到一个错误:方法sleep(int)未定义Thread类型.我认为sleep方法在Java中的Thread类中.
import java.util.Random;
public class Thread implements Runnable {
String name;
int time;
Random r = new Random();
public Thread(String s){
name = s;
time = r.nextInt(999);
}
public void run() {
try{
System.out.printf("%s is sleeping for %d\n", name, time);
Thread.sleep(time);
System.out.printf("%s is done", name);
} catch(Exception e ) {
}
}
}
Run Code Online (Sandbox Code Playgroud)