编写一个多线程程序,此程序中包含2个线程,要求:第一个线程能够计算1+2+3+...+1000的值
展开全部
package example_2;
public class Example3 extends Thread{
private int ip;
public Example3(int n){
ip = n;
}
public void run(){
int i = 0;
int total = 0;
for(;i <= ip;i++){
total += i;
}
System.out.println("total[" + ip + "] = " + total);
}
public static void main(String[] args) {
Example3 example3 = new Example3(1000);
Example3 example= new Example3(10);
example3.start();
example.start();
}
}
public class Example3 extends Thread{
private int ip;
public Example3(int n){
ip = n;
}
public void run(){
int i = 0;
int total = 0;
for(;i <= ip;i++){
total += i;
}
System.out.println("total[" + ip + "] = " + total);
}
public static void main(String[] args) {
Example3 example3 = new Example3(1000);
Example3 example= new Example3(10);
example3.start();
example.start();
}
}
更多追问追答
追问
伙计你是学java的吗,我这还有几道题,能给我说说吗,谢谢了
追答
说吧,不过不保证一定给你解决
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询