public class Ttt {
public static void main(String[] args) {
int[][] a=new int[10][10];
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
{
if (j<i)
{
a[i][j]=1;
if(j==0){
a[i][j]=1;
}else{
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}else{
a[i][j]=1;
}
} for(int i=0;i<10;i++)
{
for(int k=1;k<=10-i;k++)
System.out.printf(" "); for(int j=0;j<=i;j++){
System.out.printf("%3d ",a[i][j]);
}
System.out.printf("\n");
}
}
}
运行结果:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
心得:
1用java打印等腰三角形的杨辉三角的时候,容易打印成直角三角形,注意下标的变化
2注意前后赋值语句的调整
3调试程序的时候应多调试几次
打印等腰三角形的杨辉三角
猜你喜欢
转载自www.cnblogs.com/ltx515/p/10630206.html
今日推荐
周排行