Buonasera oggi il mio professore di tps ci ha assegnato un esercizio a casa.
Ho provato a farlo, pero riscontro un errore e non so come poterlo risolvere.
main:
codice:
package thread;
import java.util.*;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("unused")
int x = 0,y = 0,z = 0,k;
@SuppressWarnings("resource")
Scanner input= new Scanner(System.in);
//System.out.println("inserire un valore di x");
//x=input.nextInt();
//System.out.println("inserire un valore di y");
//y=input.nextInt();
//System.out.println("inserire un valore di z");
//z=input.nextInt();
t1 t1=new t1(x);
t2 t2=new t2(y);
t3 t3=new t3(z);
t1.start();
t2.start();
t3.start();
System.out.println(k=(t1.x)+t2.y+t3.z);
t1.stop();
t2.stop();
t3.stop();
t4 t4=new t4(z,y);
int t=t4.t();
t5 t5 = new t5(x,t);
System.out.println(t);
}
}
codice:
package thread;
public class t1 extends Thread {
int x,a=2,b=3,c=4;
public t1(int x) {
super();
this.x = x;
}
public void run(){
x=3*(a-1);
System.out.println(x);
}
public int x(){
return x;
}
}
codice:
package thread;
public class t2 extends Thread {
int y,a=2,b=3,c=4;
public t2(int y) {
super();
this.y = y;
}
public void run(){
y=2*(b-2);
}
public int y(){
return y;
}
}
codice:
package thread;
public class t3 extends Thread {
int z,a=3,b=2,c=4;
public t3(int z) {
super();
this.z = z;
}
public void run(){
z=3*(c-3);
}
public int z(){
return z;
}
}
codice:
package thread;
public class t4 extends Thread {
int z,y,t;
public t4(int z,int y) {
super();
this.z = z;
this.y=y;
}
public void run(){
t=y*z;
}
public int t(){
return t;
}
}
codice:
package thread;
public class t5 extends Thread {
int k,x,t;
public t5(int x,int t) {
super();
this.x = x;
this.t=t;
}
public void run(){
k=x+t;
}
public int k(){
return k;
}
}
il problema sta nell'output ottengo questo risultato
non riesco a ottenere il valore sfruttando il getter qualcuno ha qualche possibile soluzione ?