1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import java.util.Scanner; /** * Java_2018_04_11_HW2 * Author:Dragonyue */ public class Java_2018_04_11_HW2 { public static void main(String[] args) { // TODO 自動產生的方法 Stub Scanner scanner = new Scanner(System.in); System.out.print("輸入:"); int num = Integer.parseInt(scanner.nextLine()); for (int i = 0; i < num; i++) { for (int j = 0; j <= i; j++) { System.out.print(PSC(i, j) + " "); } System.out.println(); } } public static int PSC(int r, int c) { if (r == c || c == 0) return 1; else return PSC(r - 1, c) + PSC(r - 1, c - 1); } } |