Java 如何制作倒置的二维三角形阵列并填充它';s值及其总和';s索引?
我正在研究JavaRush课程中的一个问题:Java 如何制作倒置的二维三角形阵列并填充它';s值及其总和';s索引?,java,Java,我正在研究JavaRush课程中的一个问题: 从0到N创建二维三角形数组 用等于其索引总和的值填充它 打印出来 所以迪奥是这样的: 我已经解决了这个问题。但我想尝试用其他方法填充一个倒三角形数组 像这样: 像这样: 就像这样: 但我脑子里的逻辑混乱不堪 你们能帮我提些建议吗?(提前谢谢。) 这是课程中默认问题的代码: public class TriangleArray { public static int[][] result = new int[3][]; public
public class TriangleArray {
public static int[][] result = new int[3][];
public static void main(String[] args) {
for (int row = 0; row < result.length; row++) {
result[row] = new int[row + 1];
for (int col = 0; col < result[row].length; col++) {
result[row][col] = row + col;
System.out.print(result[row][col] + " ");
// if want better looking columns, may use this:
// System.out.printf("%2d ", result[row][col], " ");
}
System.out.println();
}
}
}
public类TriangleArray{
公共静态int[][]结果=新int[3][];
公共静态void main(字符串[]args){
for(int row=0;row
查看每个案例的缺失索引的共同点。请注意,在第一种情况下,隐藏值是[0][1]、[0][2]和[1][2]。对于[0][1],0<1。对于[0][2],0<2。对于[1][2],1<2。
0
1 2
2 3 4
0 1 2
1 2
2
0 1 2
2 2
4
2
2 2
2 3 4
public class TriangleArray {
public static int[][] result = new int[3][];
public static void main(String[] args) {
for (int row = 0; row < result.length; row++) {
result[row] = new int[row + 1];
for (int col = 0; col < result[row].length; col++) {
result[row][col] = row + col;
System.out.print(result[row][col] + " ");
// if want better looking columns, may use this:
// System.out.printf("%2d ", result[row][col], " ");
}
System.out.println();
}
}
}