I am trying to work in this code for weeks. I need to convert rows and columns in a 2d array to blocks. it should work on any matrix in size n*n. (that I have been given the siz
No Need to perform a complex logic. Try to use :
public static int[][] blocks(int[][] matrix, int sqrtN) { int[][] blocks = matrix; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix.length; j++){ blocks[i][j] = (i % sqrtN * sqrtN) + (j % sqrtN + 1) ; } } return blocks; }