import java.util.Scanner;
class Demo26{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入这个数组的长度");
int cd = sc.nextInt();
int[][]yh = new int [cd][cd];
for(int i = 0; i<yh.length ; i++)
{
for(int j = 0; j<=i ; j++)
{
if(i==0||i==1)
{
yh[i][j] = 1;
}else
{
if(j==0||j==i)
{
yh[i][j] = 1;
}else
{
yh[i][j] = yh[i-1][j]+yh[i-1][j-1];
}
}
}
}
for(int i = 0; i<yh.length;i++){
for(int j = 0; j<=i ; j++){
System.out.print(yh[i][j] + "\t");
}
System.out.println();
}
}
} |
|