题目内容
classComputationextendsThread{
privateintnum;
privatebooleanisComplete;
privateintresult;
publicComputation(intnum){this.num=num;}
publicsynchronizedvoidrun(){
result=num*2;
isComplete=true;
notify();
}
publicsynchronizedintgetResult(){
while(!isComplete){
try{
wait();
}catch(InterruptedExceptione){}
}
returnresult;
}
publicstaticvoidmain(String[]args){
Computation[]computations=newComputation[4];
for(inti=0;i<computations.length;i++){
computations[i]=newComputation(i);
computations[i].start();
}
for(Computationc:computations)
System.out.print(c.getResult()+);
}
}
Whatistheresult?()
查看答案
搜索结果不匹配?点我反馈
更多问题