|||
来这个网站学学吧~~一个很好的自学网http://www.51zxw.net/study.asp vip=124865
边的位置 t; /*输入高度*/ for (i=1;i<=5;i++) { for (j=1;j<=5;j++) /*定位到第i行第j列*/ { r=i;d=0;pl=j-r; if (r>5-j+1) {r=5-j+1;d=1;pl=i-r;} if (r>5-i+1) {r=5-i+1;d=2;pl=5-j+1-r;} if (r>j) {r=j;d=3;pl=5-i+1-r;} /*找出圈数 pl d b l r j 6); matrix.fill(); matrix.printMatrix(); }}
|||
public class File06 { /** * @param args the command line arguments */ public static void main(String[] args) { int i y = 0; index <= count; index++) { array[x][y] = index; switch(direct) { case 0: //向右 if(y < n - round) y++; else { direct = 1; x++; } break; case 1: if(x < m - 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; } } } private void printMatrix() { DecimalFormat df = new DecimalFormat(" 000"); for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) System.out.print(df.format(array[i][j])); System.out.println(); } } public static void main(String[] args) { ScrewSquare matrix = new ScrewSquare(8 x = 0 int n) { this.m = m; this.n = n; array = new int[m][]; for(int i = 0; i < m; i++) array[i] = new int[n]; } private void fill() { int count = m * n; int direct = 0; int round = 1; for(int index = 1 n; public ScrewSquare(int m
我只能给你java版的 public class ScrewSquare { private int[][] array; private int m 在边上的位置*/ l=5-2*(r-1);/*边长*/ b=5*5-l*l+1;/*用面积计算*/ /*本圈开始的数字*/ t=b+(l-1)*d+pl; if(t/10==0) System.out.print(t+" "); else System.out.print(t+" ");/*打印数字*/ } System.out.print("/n"); }} // TODO code application logic here }
|||
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 直接一排一排输出啊
|||
是用QB编吗
一JAVA习题
本文详细介绍了使用Java实现的一种特殊矩阵打印方式——螺旋矩阵打印。该算法从外向内逐层遍历矩阵,并按特定顺序打印元素。适用于需要对二维数组进行特殊遍历的应用场景。

被折叠的 条评论
为什么被折叠?



