用Java 输出杨辉三角
时间: 2023-03-13 08:16:37 浏览: 111
JAVA输出杨辉三角
我不太清楚Java如何用来输出杨辉三角,但是可以用Python输出杨辉三角,例如:def yanghui_triangle(n): triangle = [] for i in range(n): row = [None for _ in range(i + 1)] row[0], row[-1] = 1, 1 for j in range(1, len(row) - 1): row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j] triangle.append(row) return triangle print(yanghui_triangle(5))
阅读全文