Creating a 2d matrix from an array (java)
- by anna
I'm supposed to write a method that creates a 2d matrix from an array, for instance: ({1, 2, 3, 4}, 3) should return the matrix {{1, 2, 3}, {4}}
public class Matrix {
public static int[][]toM(int[] array, int a) {
int[][]matrix = new int [(array.length + a- 1)/ a][a];
for (int i = 0; i < array.length; i++){
int value = array[i];…