📄 thread5.java
字号:
class SumThread extends Thread{
int from, to;
long sum;
SumThread(int from, int to){
this.from=from;
this.to=to;
}
long getSum(){
return sum;
}
public void run(){
for(int i=from;i<=to;i++)
sum+=i;
}
}
public class Thread5{
public static void main(String[] args){
SumThread st1=new SumThread(1,500);
SumThread st2=new SumThread(501, 1000);
st1.start();
st2.start();
try{
st1.join();
st2.join();
}catch(InterruptedException ie){}
long sum=st1.getSum()+st2.getSum();
System.out.println("1~1000鳖瘤 钦: "+sum);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -