I'm a long time surfer, first time asker.
I started teaching myself java a month ago with almost no programming experience (other than GUI based programming for Lego Mindstorms kits).
I'm testing a program that involves integer arrays that are filled with random numbers. I have to ensure that none of the arrays are equal. So, I went with a while loop that won't end until the comparison check for all arrays is complete. Here's the test code I'm using:
import java.util.Arrays;
public class testmain {
public static void main (String[] args){
int[] testint1 = new int[2];
int[] testint2 = new int[2];
int[] testint3 = new int[2];
int[] testint4 = new int[2];
boolean donecheck = false;
while (donecheck == false){
testint1[0] = (int) (Math.random() * 4);
testint1[1] = (int) (Math.random() * 4);
testint2[0] = (int) (Math.random() * 4);
testint2[1] = (int) (Math.random() * 4);
testint3[0] = (int) (Math.random() * 4);
testint3[1] = (int) (Math.random() * 4);
testint4[0] = (int) (Math.random() * 4);
testint4[1] = (int) (Math.random() * 4);
if (testint1 != testint2){
if (testint1 != testint3){
if (testint1 != testint4){
if (testint2 != testint3){
if (testint2 != testint4){
if (testint3 != testint4){
donecheck = true;
}
}
}
}
}
}
}
System.out.print (Arrays.toString(testint1));
System.out.print (Arrays.toString(testint2));
System.out.print (Arrays.toString(testint3));
System.out.print (Arrays.toString(testint4));
}
}
I get same valued integer arrays despite this. What am I doing wrong? Should I try something different.
Thank you for your help.
Regards