I'm matching the value of each of the 2D array against 1D Array. 1D array is actually the conversion of 2D to 1D array, so that i can use Arrays.sort() to sort the array to ascending order. However when i'm printing out, it give me extra values. I should have 6 values printed out only.
Code:In score 2D array: [ i ] [ j ] [ value ] 0 0 1.0 0 1 0.04 1 0 0.24 1 1 1.0 2 0 0.15 2 1 0.14Code:Before sorting newArray 1D array: [ a ] [ value ] 0 1.0 1 0.24 2 0.24 3 1.0 4 0.15 5 0.14Code:After sorting newArray 1D array: [ a ] [ value ] 0 0.14 1 0.15 2 0.24 3 0.24 4 1.0 5 1.0Here is my code:Code:The output is: [ i ] [ j ] newArray[a] 2 1 0.14 2 0 0.15 0 1 0.24 1 0 0.24 0 1 0.24 //this is repeated 1 0 0.24 //this is repeated 0 0 1.0 1 1 1.0 0 0 1.0 //this is repeated 1 1 1.0 //this is repeated
How can I check if the value is printed out once, it would not print it out again?Code:queryIDArray(length of 3) and srnIDArray(length of 2) are all 1D arrays. public static void sortArray(float[][] score) { int k=0; float[] newArray = new float[queryIDArray.length*scrnIDArray.length]; for(int i=0;i<queryIDArray.length;i++) { for(int j=0;j<scrnIDArray.length;j++) { newArray[k] = score[i][j]; k++; } } Arrays.sort(newArray); for(int a=0;a<newArray.length;a++) { for(int i=0;i<queryIDArray.length;i++) { for(int j=0;j<scrnIDArray.length;j++) { if(newArray[a]==score[i][j]) System.out.println(i+" "+j+" "+newArray[a]); //what condition should I put so that it will not repeat? } } } }




Reply With Quote