Hi guys,
I can't figure out how to proceed and whether I'm in the right way to resolve this task.
Pls, gimme a hint(s).
1. Should I fill a new 2d Array result by adding the values from the two other arrays result1 and result2
2. Which method(s) would be suitable here?
Thank you in advance!
package en.codegym.task.pro.task05.task0517;
import java.util.Arrays;
/*
Splitting an array
*/
public class Solution {
public static int[][] result = new int[2][];
public static int[] array = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
public static void main(String[] args) {
if (array.length % 2 == 0) {
int[] result1 = Arrays.copyOfRange(array, 0, array.length/2);
int[] result2 = Arrays.copyOfRange(array, array.length/2, array.length);
result = new int[result1.length][result2.length];
System.out.println(Arrays.deepToString(result));
} if (array.length % 2 != 0) {
int[] result1 = Arrays.copyOfRange(array, 0, array.length/2+1);
int[] result2 = Arrays.copyOfRange(array, array.length/2+1, array.length);
result = new int[result1.length][result2.length];
System.out.println(Arrays.deepToString(result));
}
}
}