PHP預定義變數陣列種類概覽
阿新 • • 發佈:2022-05-03
import java.util.Scanner;
public class Class {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("列印楊輝三角形的行數:");
int row = scanner.nextInt();
int[][] a = new int[row][];
for (int i = 0; i < a.length; i++) {
a[i] = new int[i + 1];
for (int j = 1; j <= row - i; j++) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
a[i][j] = 1;
} else {
a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
}
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}