java 问题为下列Java图案编程 1 3 6 10 15 2 5 9 14 4 8 13 7 12 11 望高手帮忙

2024-12-21 14:37:33
推荐回答(1个)
回答1:

这有什么难度
public class Dragon {

public static void main(String[] args) {

final int size = 5;

int[][] ary = new int[size][size];

int num = 1;

for(int row = 0; row < ary.length; row++){
for(int i = row, col = 0; i >= 0; i--){
ary[i][col++] = num++;
}

}
for(int[] aryItem : ary){
for(int value: aryItem){
if(value != 0){
System.out.print(value + " ");
}
}
System.out.println();
}

}
}

---------------
1 3 6 10 15
2 5 9 14
4 8 13
7 12
11