1 import java.util.Scanner; 2 3 public class Yanghui { 4 public static void main(String[] args) { 5 Scanner sc = new Scanner(System.in); 6 System.out.println("请输入行列数"); 7 int num = sc.nextInt(); 8 int[][] a = new int[num][num]; 9 for (int i = 0; i < a.length; i++) {10 for (int j = 0; j < i + 1; j++) {11 // 输出所有的1,其他的数再想办法12 a[i][0] = 1;13 a[i][i] = 1;14 if (i >= 2 && j >= 1) {15 // 从第三行起,中间的不等于1的数的值其实是上一个一位数组的两个相邻元素的和16 a[i][j] = a[i - 1][j - 1] + a[i - 1][j];17 }18 System.out.print(a[i][j] + "\t");19 }20 System.out.println();21 }22 }23 }24 请输入行列数25 426 1 27 1 1 28 1 2 1 29 1 3 3 1
public class MyYanghui { public static void main(String[] args) { int num = 8; int[][] arr =new int[num][num]; for(int i =0;i