Java编写杨辉三角

    xiaoxiao2022-06-29  36

    package com.test.cn; public class YangHui{ public static void main(String[] args) { for (int i = 0; i < 10; i++) { for (int j = 0; j < i + 1; j++) { int num = 1; for (int k = 0; k < j; k++) { num = num * (i - k) / (k + 1); } System.out.print(" " + num + " "); } System.out.println(); } }

    }

    ======================================

    1   1  1   1  2  1   1  3  3  1   1  4  6  4  1   1  5  10  10  5  1   1  6  15  20  15  6  1   1  7  21  35  35  21  7  1   1  8  28  56  70  56  28  8  1   1  9  36  84  126  126  84  36  9  1 

    转载请注明原文地址: https://ju.6miu.com/read-1125277.html

    最新回复(0)