Hey. I need a method that creates a matrix from an array, for instance:
({10, 11, 12, 13}, 2) should return {{10, 11, 12}, {13}}.
public class Matrix{
public static int[][]toM(int[] array, int a){
int[][]matrix = new int [(array.length)/a][a];
for (int i = 0; i < array.length; i++){
int value = array[i];
for (int row = 0; row < (array.length + 1)/n; row++){
for (int col = 0; col < n; col++){
matrix[row][col]= value;
}
}
}
return matrix;
}
public static void main(String[]args){
int[]array= {1,2,3,4};
int a= 2;
System.out.println(toM(array, a));
}
When I try to test the method, I only get [[I@9314b1, [I@193d11, [I@a9053] etc. I know that array.length/a is wrong but I'm confused to how I'm supposed to do. I'm completely new to this stuff so I appreciate all help I can get!