描述如下:
n=1时:
输出 0 1 0
4 5 2
0 3 0
n=2时:
输出:
0 1 2 0
8 9 10 3
7 12 11 4
0 6 5 0
依次类推,螺旋输出。
n=1时:
输出 0 1 0
4 5 2
0 3 0
n=2时:
输出:
0 1 2 0
8 9 10 3
7 12 11 4
0 6 5 0
依次类推,螺旋输出。
解决方案 »
- java界面设计问题
- 我想做一个象EXCEL那样的窗口框架,外面是菜单栏,工具栏,然后每打开一个表就显示在下面的区域里应该怎样做?可以给个例子吗?谢谢!,
- 发一个小有点意思的题目,写出运行结果!
- 请教:BasicComboBoxRenderer这个类
- 程序等待输入的问题,这是问第二遍了!谢谢了
- 今天的作业不会了~问问各位大虾...
- java applet能调用jdbc吗?初学,请指教!
- 关于include、plugin、@ page等的比较问题,希望各位高手指教
- 请注意,我来说一点,关于程序员薪金问题
- 关于用C和java读同一个二进制文件却结果不同的问题
- 焦点在控件之间的移动
- 一个关于elipse 的问题
public class HelixTest
{
private static int[][] helixNum(int n) {
int len=n+2;
int[][] array=new int[len][len];
int count = len*len-4;
int direct = 0;
int round = 1;
for(int index = 1, x = 0, y = 0; index <= count; index++) {
if(((x==0)&&(y==0||y==len-1))||(x==len-1)&&(y==0||y==len-1)){
array[x][y]=0;
index--;
}
else{
array[x][y] = index;
}
switch(direct) {
case 0:
if(y < len - round)
y++;
else {
direct = 1;
x++;
}
break;
case 1:
if(x < len - round)
x++;
else {
direct = 2;
y--;
}
break;
case 2:
if(y >= round)
y--;
else {
direct = 3;
x--;
}
break;
case 3:
if(x > round)
x--;
else {
direct = 0;
round++;
y++;
}
break;
}
}
return array;
}
public static void main(String[] args){
int[][] intArr=helixNum(2);
for(int i=0;i<intArr.length;i++){
for(int j=0;j<intArr[i].length;j++){
System.out.print(intArr[i][j]+" ");
}
System.out.println();
} }
}