//In java
package ds1;
public class SpiralMatrix {
public static void main(String[] args) throws Exception{
int[][] values = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};
int x=0,y=0,z=0 ,length=values.length;
System.out.println("Jai ShRaam \n array size :"+length+" \n \n");
//Logic Starts
for (int i=0;i<values.length;i++ )
{
for (int j=0;j<values.length;j++ )
{
if(i==j){
for(int k=i;k<length-i;k++)
{
System.out.print(values[x][k]+" , ");
}
x++;y++;
for(int k=x;k<length-i;k++)
{
System.out.print(values[k][length-x]+" ; ");
}
y++;
for(int k=i+length-y;k>=i;k--)
{
System.out.print(values[length-x][k]+" - ");
}
for(int k=i+length-y;k>=x;k--)
{
System.out.print(values[k][i]+" : ");
}
}//end of i==j
}//end of j loop
//System.out.println();
}
//Logic ends
}//end of psvm
}
//Answer
1 , 2 , 3 , 4 , 5 , 10 ; 15 ; 20 ; 25 ; 24 - 23 - 22 - 21 - 16 : 11 : 6 : 7 , 8 , 9 , 14 ; 19 ; 18 - 17 - 12 : 13 ,