杨辉三角与二项式系数

杨辉三角与二项式系数

杨辉三角与二项式系数

杨辉三角与二项式系数

杨辉三角与二项式系数

package test;

public class YanghuiTriangleExample {
    
    public static void main(String[] args) {
        int rows = 10;

        for(int i =0;i<rows;i++) {
            int number = 1;
            //打印空格字符串
            System.out.format("%"+(rows-i)*2+"s","");
            for(int j=0;j<=i;j++) {
                //最大的数是三位的,空四个位置,比较粗略
                 System.out.format("%4d",number);
                 //当前数= 前一个数*(行-列)/(列+1) ------------ 二项式系数
                 number = number * (i - j) / (j + 1);                
            }
            System.out.println();
        }
    }
}

参考:https://blog.csdn.net/baidu_37107022/article/details/72853001?from=timeline

相关文章:

猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-05-19
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案