输入n,打印出下图:(N=5)1 16 15 14 132 17 24 23 123 18 25 22 11 4 19 20 21 105 6 7 8 9
明天就要,快点!
明天就要,快点!
解决方案 »
- 请各位大侠帮忙!不胜感激!
- 关于 java swing 中的按钮 如何实现用键盘来操作 急 !急 ! 能举个例子 更好
- 请问一个将字符串转换为long的程序
- java学习交流群 16918020 欢迎大家参与.有经验的,70年代的优先,呵呵
- java 编译初级问题,望大家多多帮忙
- JAVA 版 OICQ
- 说说自己学习Java的方法
- 请教各位高手我想判断字符串是数字.
- 关于JTextArea.
- Properties类的getProperty(String key, String defaultValue) 中的defaultValue是什么意思?
- rt.jar ,dt.jar ,tool.jar是什么东西,什么时候需加到到classpath
- 如何获得mysql数据库中表的字段名和字段的注释信息
int[][] myMatrix = new int[20][20];
static int H = 5;
static int L = 4;
static int count = 0; //填充数字记数
int hh=H; //矩阵实际大小
int ll=L;
int stepX = hh; //初始步距
int stepY = 6-1;
int x=0; //初始坐标
int y=0; void fillFromLeftToRight(int step) {
for (int i=0; i<step; i++) {
if (myMatrix[y][x]==0) { myMatrix[y][x] = ++count; }
else { x++; myMatrix[y][x] = ++count; }
}
};
void fillFromUpToDown(int step) {
for (int i=0; i<step; i++) {
y++;
myMatrix[y][x] = ++count;
}
};
void fillFromRightToLeft(int step) {
for (int i=0; i<step; i++) {
x--;
myMatrix[y][x] = ++count;
}
};
void fillFromDownToUp(int step) {
for (int i=0; i<step; i++) {
y--;
myMatrix[y][x] = ++count;
}
};
public void make() {
do {
if (count != H*L) fillFromLeftToRight(stepX--);
if (count != H*L) fillFromUpToDown(stepY--);
if (count != H*L) fillFromRightToLeft(stepX--);
if (count != H*L) fillFromDownToUp(stepY--);
} while (count!=H*L);
};
public void prtMatrix() {
for (int i=0; i<L; i++) {
for (int j=0; j<H; j++)
if (myMatrix[i][j] < 5) System.out.print(" "+myMatrix[i][j]);
else if (myMatrix[i][j] >= 100) System.out.print(" "+myMatrix[i][j]);
else System.out.print(" "+myMatrix[i][j]);
System.out.println();
}
};
}public class juZhen {
public static void main(String[] args) {
HelixMatrix aa = new HelixMatrix();
aa.make();
aa.prtMatrix();
}}
int[][] myMatrix = new int[20][20];
static int H = 5;
static int L = 4;
static int count = 0; //填充数字记数
int hh=H; //矩阵实际大小
int ll=L;
int stepX = hh; //初始步距
int stepY = 6-1;
int x=0; //初始坐标
int y=0; void fillFromLeftToRight(int step) {
for (int i=0; i<step; i++) {
if (myMatrix[y][x]==0) { myMatrix[y][x] = ++count; }
else { x++; myMatrix[y][x] = ++count; }
}
};
void fillFromUpToDown(int step) {
for (int i=0; i<step; i++) {
y++;
myMatrix[y][x] = ++count;
}
};
void fillFromRightToLeft(int step) {
for (int i=0; i<step; i++) {
x--;
myMatrix[y][x] = ++count;
}
};
void fillFromDownToUp(int step) {
for (int i=0; i<step; i++) {
y--;
myMatrix[y][x] = ++count;
}
};
public void make() {
do {
if (count != H*L) fillFromLeftToRight(stepX--);
if (count != H*L) fillFromUpToDown(stepY--);
if (count != H*L) fillFromRightToLeft(stepX--);
if (count != H*L) fillFromDownToUp(stepY--);
} while (count!=H*L);
};
public void prtMatrix() {
for (int i=0; i<L; i++) {
for (int j=0; j<H; j++)
if (myMatrix[i][j] < 5) System.out.print(" "+myMatrix[i][j]);
else if (myMatrix[i][j] >= 25) System.out.print(" "+myMatrix[i][j]);
else System.out.print(" "+myMatrix[i][j]);
System.out.println();
}
};
}public class juZhen {
public static void main(String[] args) {
HelixMatrix aa = new HelixMatrix();
aa.make();
aa.prtMatrix();
}}