I hope you can help me, I have this thread problem ... Create a program that evaluates
p = Σfrom i = -100 to 100 (sin (i)) + Σfrom i = -100 to 100 of (cosine (i)) + Σfrom i = -100 to 100 of (tangent (i))
For each term in the equation, use a thread and at the end perform the addition.
I have this, this is the sum 1 of the breast ...
public class Suma1 extends Thread{
public Suma1(String msg){
super(msg);
}
@Override
public void run(){
int i;
double s=0;
for(i=-100;i<=100;i++){
s+=(s+Math.sin(i));
}
System.out.println("Hilo 1");
System.out.println(s);
}
}
For the sum 2 of the cosine is this ...
public class Suma2 extends Thread{
public Suma2(String msg){
super(msg);
}
@Override
public void run(){
int i;
double s=0;
for(i=-100;i<=100;i++){
s+=(s+Math.cos(i));
}
System.out.println("Hilo 2");
System.out.println(s);
}
}
and for the sum 3 of the tangent, this is ...
public class Suma3 extends Thread{
public Suma3(String msg){
super(msg);
}
@Override
public void run(){
int i;
double s=0;
for(i=-100;i<=100;i++){
s+=(s+Math.tan(i));
}
System.out.println("Hilo 3");
System.out.println(s);
}
}
This is my main ...
public class HiloNum7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Thread hilo1=new Suma1("Proceso numero 1");
Thread hilo2=new Suma2("Proceso numero 2");
Thread hilo3=new Suma3("Proceso numero 3");
Thread hilo4=new SumaTotal("Proceso numero 4");
hilo1.start();
hilo2.start();
hilo3.start();
hilo4.start();
}
}
What I can not do is the general sum, I hope you can help me, my idea was to create another thread to add the 3 threads, but I have not the slightest idea how to do it: (