Netbeans is giving me the wrong sum.
int[] x=new int[2];
int[] y=new int[2];
Data data=new Data();
Random rand=new Random();
int r1,r2;//Results of random numbers.
r1=rand.nextInt(2);
System.out.println("First random number is: "+r1);
r2=rand.nextInt(2);
System.out.println("Second random number is: "+r2);
if(r1==0){
x=data.a();
}else if(r1==1){
x=data.b();
}
if(r2==0){
y=data.a();
}else if(r2==1){
y=data.b();
}
int result=x[0]+y[0];
System.out.println("The sum is: "+result);
//I get the wrong sum when I get '1' and '0'.
This is a the java class of the data.
int[] x=new int[2];
public int[] a(){
x[0]=300;
x[1]=3;
return x;
}
public int[] b(){
x[0]=250;
x[1]=2;
return x;
}
I don´t know why it is giving me the wrong answer. Thanks in advance.