解题思路:
import java.util.Scanner; public class C1231 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { F(sc.nextInt()); } sc.close(); } private static void F(int n){ int[][] a = new int[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ if(j == 0 || i == j) a[i][j] = 1; else a[i][j] = a[i-1][j] + a[i-1][j-1]; } } for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ if(j < i) System.out.printf("%d ", a[i][j]); else System.out.printf("%d\n", a[i][j]); } } System.out.println(); } }
注意事项:
参考代码:
0.0分
1 人评分