Class Array Job
{/********1.1 is always in the middle of the first line;
2. Next number, always fill in the upper right corner;
3. If there is no position in the upper right corner, turn around (two cases)
4. If a multiple of n is encountered, a number is directly below it.
********/
public static void Main (string[] args)
{
int n=11;
Int[][] a= new Int[n][n];
int i=0; int J=N/2;
A[i][j]=1;
for (int k=2; k<=n*n;k++)
{
if (a[i][j]%n==0)
{
A[i+1][j]=k;
i=i+1;
}
else if (i==0)
{
A[n-1][j+1]=k;
i=n-1;
j=j+1;
}
else if (j==n-1)
{
A[i-1][0]=k;
I=i-1;
j=0;
}
Else
{
A[i-1][j+1]=k;
I=i-1;
j=j+1;
}
}
for (int p=0;p<n;p++)
{
for (int q=0;q<n;q++)
{
if (q==n-1)
{
System.out.println ("+a[p][q");
}
Else
System.out.print ("+a[p][q");
}
}
}
}
This article is from the "64 Tiger" blog, be sure to keep this source http://doubletiger.blog.51cto.com/11157348/1747228
My Java Learning array job