1. 代码
public static void main(String[] args) { int[][] triangle = new int[10][]; for(int i=0; i<10; i++){ triangle[i] = new int[i+1]; for(int j=0; j<=i; j++){ if(j==0 || i==0 || j==i){ triangle[i][j] = 1; }else{ triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; } System.out.print(triangle[i][j] + " "); } System.out.println(); } }
2.运行效果图