導入Java . util . random;
公共類電話{
公共靜態void main(String[] args) {
D3D d3d1 =新D3D(1,1000);
D3D d3d2 =新D3D(22000);
D3D d3d3 =新D3D(33000);
Thread th1 =新線程(d3d 1);
線程th2 =新線程(d3d 2);
Thread th3 =新線程(d3d 3);
th3 . start();
TH2 . start();
th 1 . start();
}
}類實現Runnable
{私有int sum
私有int g;
公共D3D(整數,整數和)
{
this.sum = sum
this.g = g
}
公共無效運行(){
嘗試{
Thread.sleep(總和);
系統。out . println(" 3D的抽獎結果-"+g+"號是"+go());
} catch (InterruptedException e) {
e . printstacktrace();
}
}
public int go()
{
Random ra = new Random();
返回ra . nextint(9);
}
}
結果