java - Ensure that randomly generated int[] arrays aren't equal -


i'm long time surfer, first time asker.

i started teaching myself java month ago no programming experience (other gui based programming lego mindstorms kits).

i'm testing program involves integer arrays filled random numbers. have ensure none of arrays equal. so, went while loop won't end until comparison check arrays complete. here's 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 same valued integer arrays despite this. doing wrong? should try different.

thank help.

regards

these 2 options check if object same, i.e. same array.

array1 == array2 

and

array1.equals(array2) 

to compare contents of arrays need use:

arrays.equals(array1, array2)  

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -