java 问题为下列Java图案编程 1 3 6 10 15 2 5 9 14 4 8 13 7 12 11 望高手帮忙
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询