I am not getting the desired output in question spiralprintclockwise

import java.util.;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][m];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
arr[i][j] = sc.nextInt();
}
System.out.println();
}
printspiral(arr);
sc.close();
}
public static void printspiral(int [][]arr){
int top=0,bottom=arr.length-1,left=0,right=arr[top].length-1,dir=1,count=(bottom+1)
(right+1);
while(left<=right && top<=bottom){
if(count>0){
if(dir==1){
for(int i=left;i<=right;i++){
System.out.print(arr[top][i]+", “);
count–;
}
dir=2;
top++;
}
}
if(count>0){
if(dir==2){
for(int i=top;i<=bottom;i++){
System.out.print(arr[i][bottom]+”, “);
count–;
}
dir=3;
right–;
}
}
if(count>0){
if(dir==3){
for(int i=right;i>=left;i++){
System.out.print(arr[bottom][i]+”, “);
count–;
}
dir=4;
bottom–;
}
}
if(count>0){
if(dir==4){
for(int i=bottom;i>=top;i++){
System.out.print(arr[i][left]+”, ");
count–;
}
dir=1;
left++;
}
}
}
System.out.println(“END”);
}
}
where is the error?

Your code isn’t formatted properly, (Some symbols miss out while sharing the code this way).
Kindly share your code using the online IDE.

where is this online ide

Just paste your code (the original one, not this one).
Save it and share the corresponding link here.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.