这个怎么打印 1 2 3 416 15 14 511 12 13 610 9 8 7 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.out.println("1 2 3 4");System.out.println("16 15 14 5");System.out.println("11 12 13 6");System.out.println("10 9 8 7"); 你自己出的题就没有归律,一下顺时针,一下倒时针.应该是这样才有归律吧.1 2 3 412 13 14 511 16 15 610 9 8 7public class Demo { public static void main (String[] args) { final int a=4, b=4; //定义矩阵 int n=1; //和打印排版有关 while (n<a*b) n*=10; n=n*n/10; int[][] arr = new int[a][b]; int x=0,y=0,s=1; arr[x][y] = s; while (s<a*b) { //以下四个循环换下顺序可变成顺时针 while ( y+1<b && arr[x][y+1]==0 ) { y++; s++; arr[x][y]=s; //right } while ( x-1>=0 && arr[x-1][y]==0 ) { x--; s++; arr[x][y]=s; //up } while ( y-1>=0 && arr[x][y-1]==0 ) { y--; s++; arr[x][y]=s; //left } while ( x+1<a && arr[x+1][y]==0 ) { x++; s++; arr[x][y]=s; //down } } for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { int m=arr[i][j]; while ( m<n ){ //打印排版有关 System.out.print (" "); m*=10; } System.out.print (arr[i][j]); } System.out.println (""); } }} 利用 java 将 UTF-8 文件转换成中文问题 java socket 方面 请求大家帮助!!(100分) 一道题目,希望大家发表下意见(答案将在5楼给出) 搞了2天了`在线求答`````````(关于struts+hibernate+spring)配置文件 接口可以实例化吗? java 運行問題 向ORACLE插入clob的错误,大家指点。 jsp and bean??? 关于接口实现解耦功能的疑问 问题请教 刚学JAVA,用JAVA改写TXT文本内容 如何学习java的io/输入输出?
System.out.println("16 15 14 5");
System.out.println("11 12 13 6");
System.out.println("10 9 8 7");
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7public class Demo {
public static void main (String[] args) {
final int a=4, b=4; //定义矩阵
int n=1; //和打印排版有关
while (n<a*b) n*=10;
n=n*n/10;
int[][] arr = new int[a][b];
int x=0,y=0,s=1;
arr[x][y] = s;
while (s<a*b) { //以下四个循环换下顺序可变成顺时针
while ( y+1<b && arr[x][y+1]==0 ) {
y++; s++; arr[x][y]=s; //right
}
while ( x-1>=0 && arr[x-1][y]==0 ) {
x--; s++; arr[x][y]=s; //up
}
while ( y-1>=0 && arr[x][y-1]==0 ) {
y--; s++; arr[x][y]=s; //left
}
while ( x+1<a && arr[x+1][y]==0 ) {
x++; s++; arr[x][y]=s; //down
}
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
int m=arr[i][j];
while ( m<n ){ //打印排版有关
System.out.print (" "); m*=10;
} System.out.print (arr[i][j]);
} System.out.println ("");
}
}
}