You still haven’t asked any question, but I assume that your program gives wrong answer (as it really do) and you don’t know why.
For example: for n=16 it prints:
1234
1234
1234
1234
The following code fragment is responsible:
array[i][j]=j+1;
System.out.print(array[i][j]);
Firstly, you don’t print spaces, so numbers aren’t separated. Secondly, you have to use another formula: i*m+j+1
(as number depends on both i
and j
). Also, there is no point in keeping array, but it’s not an error.
Suggested correction:
System.out.print(m*i+j+1 + " ");
1
solved Given N number display M*M format [closed]