class thread123 extends Thread {
public thread123(int ind, int interval) {
i0 = ind;
delay = interval;
}
public void run() {
try {
for (int i = 1; i <= 10; i++) {
if (i0 == 1) {
System.out.println("n = " + i + ", Time = " + (delay * i - delay) + ", Thread one: " + (2 * i + 5));
} else if (i0 = 2) {
System.out.println("n = " + i + ", Time = " + (delay * i - delay) + ", Thread Two: " + (i + 10) * 2);
} else {
System.out.println("n = " + i + ", Time = " + (delay * i - delay) + ", Thread Three: " + (18 * (i * i) - 12) / (i - 2);
}
sleep(delay);
}
} catch (InterruptedException e) {
return;
}
}
private int i0;
}
class Threads {
public static void main(String[] args) throws InterruptedException {
thread123 t1 = new thread123(1, 20);
thread123 t2 = new thread123(2, 3.0);
thread123 t3 = new thread123(3, 40);
t1.start();
t2.start();
t3.start();
t1.join();
t2.join();
t3.join();
System.out.println("Main thread done");
}
}
答案 0 :(得分:1)
thread123 t2 = new thread123(2, 3.0);
无效,因为thread123
只需int
s delay = interval;
无效,因为delay
未定义,因此与delay
有关的任何内容都与此相关} else if (i0 = 2) {
是和作业,而不是评估,它不等同于boolean
,因此无效System.out.println("n = " + i + ", Time = " + (delay * i - delay) + ", Thread Three: " + (18 * (i * i) - 12) / (i - 2);
错过了结束)
您可能还希望阅读Code Conventions for the Java TM Programming Language,这样可以让人们更轻松地阅读您的代码并让您阅读其他代码