
write a program in java which input n ,a natural number less than 12 and prints the natural number from 1 to n to the power 2 in the form of a spiral.the spiral should move in on anti clockwise direction starting from the entire.

Java Number Spiral
import java.util.*;
public class NumberSpiral{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter value of n(1-12): ");
int n=input.nextInt();
int sq=n*n;
int i, s = n,x=0, y=0;
int arr [][]= new int [n][n];
i=n*n;
while(i>=1){for(int j=0; j<s; j++)
arr[x][y++] = i--;
x++;
y--;
if(i>=1){for(int j=0; j<s-1; j++)
arr[x++][y] = i--;
x--;
y--;
}
if(i>=1){for(int j=0; j<s-1; j++)
arr[x][y--] = i--;
x--;
y++;
}
if(i>=1){for(int j=0; j<s-2; j++)
arr[x--][y] = i--;
y++;
x++;
s=s-2;
}
}
for(i=0; i<n; i++){
for(int j=0; j<n; j++)
System.out.print(arr[i][j] + " ");
System.out.println();
}
}
}