package Test1;
import java.util.Scanner;
public class ArrayTest3 {
public static void main(String[] args) {
// 杨辉三角形
Scanner sc = new Scanner(http://System.in);
System.out.println("请输入1~34中一个数字作为行:");
int row = sc.nextInt();
YangHui(row);
}
public static void YangHui(int row){
//建立二维数组
int [][] a = new int [row][row];
//保存row
int r = row;
//第一列和最后一列都是1
while(row >= 1){
a[row-1][0] = 1;
a[row-1][row-1] = 1;
row--;
}
//从第三行开始的规律
for(int i = 3;i <= r;i++){
for(int j = 1;j <= r-2;j++){
a[i-1][j] = a[i-2][j]+a[i-2][j-1];
}
}
//打印数组中的值
for(int i = 0;i < a.length;i++){
for(int j = 0;j < i+1;j++){
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
}