Fixed a massive bugs, please redownload

This commit is contained in:
Siwat Sirichai 2020-10-30 00:49:00 +07:00
parent cb435fae59
commit 6849efa946
5 changed files with 12 additions and 3 deletions

View File

@ -34,7 +34,7 @@ public class ArrayUtility {
if(n<=0) return new int[0][0]; //Return to prevent ArithmeticException: / by zero and negative array index if(n<=0) return new int[0][0]; //Return to prevent ArithmeticException: / by zero and negative array index
if (d.length%n!=0)return new int[0][0]; //Return, empty array, array can't be split into n equal parts if (d.length%n!=0)return new int[0][0]; //Return, empty array, array can't be split into n equal parts
int[][] splittedArray = new int[n][d.length/n]; //Create the splitted_array array and initialize it int[][] splittedArray = new int[n][d.length/n]; //Create the splitted_array array and initialize it
for(int i = 0;i < n;i++)for(int j = 0;j<d.length/n;j++)splittedArray[i][j] = d[j*n+i]; //Loop for n Row and d.length/n column, the position of 2d array is row * ROW_SIZE + column for(int i = 0;i < n;i++)for(int j = 0;j<d.length/n;j++)splittedArray[i][j] = d[i*n+j]; //Loop for n Row and d.length/n column, the position of 2d array is row * ROW_SIZE + column
return splittedArray; //send the reference back return splittedArray; //send the reference back
} }

View File

@ -2,8 +2,8 @@
public class ArrayUtilityTest { public class ArrayUtilityTest {
public static void main(String[] args) { public static void main(String[] args) {
// testMerge(); // testMerge();
// testSplit(); testSplit();
myTestSplit(); // myTestSplit();
myTestMerge(); myTestMerge();
} }

View File

@ -8,3 +8,12 @@ Player06,3,4,4,3,3,4,4,4,5,5,3,4
Player08,4,6,5,3,4,6,4,3,4,4,2,5,4,4,3,4 Player08,4,6,5,3,4,6,4,3,4,4,2,5,4,4,3,4
Player09,5,5,8,4,5,4,5,3,6,6,5,4,5 Player09,5,5,8,4,5,4,5,3,6,6,5,4,5
Player10,5,4,5,3,6,4,5,4,6,5,5 Player10,5,4,5,3,6,4,5,4,6,5,5
1,3,2,5,4 5
1,3 2
9,4,5,6 4
5+2+4 11

1 uneven
8 Player08,4,6,5,3,4,6,4,3,4,4,2,5,4,4,3,4
9 Player09,5,5,8,4,5,4,5,3,6,6,5,4,5
10 Player10,5,4,5,3,6,4,5,4,6,5,5
11 1,3,2,5,4 5
12 1,3 2
13 9,4,5,6 4
14 5+2+4 11
15
16
17
18
19