作者csdunhill (MR.阿花)
看板java
標題[問題] thread問題!!!
時間Tue Jun 24 01:48:22 2008
public void run()
{
double x,y,a;
for(int i=1;i<=looplmt;i++)
{
x=(Math.random()*edge);
y=(Math.random()*edge);
a=((x*x)+(y*y));
if(a<(edge*edge))
count=count+1;
}
System.out.println(jobname+" = "+count);
}
}
這是我run()裡的程式,我想把count回傳至main裡面
可是run()只能宣告為void,
請問有什麼方法可以做到呢?
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.64.135.252
→ Lordaeron:要宣成其它->不行,要傳值用共用變數加個event之類的就好 06/24 01:52
→ csdunhill:不懂你的意思呢~"~ 06/24 02:00
推 cgkm:public int getCount() { return count; } 06/24 02:08
推 chordee:implements Callable??? 06/24 02:11
→ csdunhill:共用變數的方法傳回來的值為0呢,是thread的關係嗎 06/24 02:18
推 Lordaeron:你的main是要等thread計算完才去讀的對吧? 06/24 11:43
→ csdunhill:對押!!! 06/24 11:54
→ csdunhill:真感謝您,我寫出來摟 06/24 12:13