COMPILATION ERROR AND WRONG ANSWER

Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int m = scn.nextInt();
int[][] a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = scn.nextInt();
}
}
int rmin = 0;
int cmin = 0;
int rmax = a.length - 1;
int cmax = a[0].length - 1;
int tn = n * m;
int cnt = 0;
while(cnt<tn) {
// top
for(int i =rmin,j=cmin;j<=cmax && cnt<=tn;j++) {
System.out.print(a[i][j] );
System.out.print(", “);
cnt++;
}
rmin++;
// right
for (int i = rmin, j = cmax; i <= rmax && cnt <= tn; i++) {
System.out.print(a[i][j]);
System.out.print(”, “);
cnt++;
}
cmax–;
// bottom
for (int i = rmax, j = cmax; j >= cmin && cnt <= tn; j–) {
System.out.print(a[i][j] );
System.out.print(”, “);
cnt++;
}
rmax–;
// left
for (int i = rmax, j = cmin; i >= rmin && cnt <= tn; i–) {
System.out.print(a[i][j]);
System.out.print(”, ");
cnt++;
}
cmin++;

}
	System.out.print("END");
}

}

your code doesn’t work for cases when n!=m

i corrected that but still getting error in case 1, case 0 passed

Input:
3 4
1 2 3 4
5 6 7 8
9 10 11 12

Expected Output:
1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7, END
Your output:
1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7, 6, END
debug for this