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

高分悬赏:Java语言怎么输出如下的三角形
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
关注
杨辉三角最本质的特征是,它的两条斜边都是由数字1组成的,而其余的数则是等于它肩上的两个数之和。
package algorithm; public class YFTriangle { public static void main(String[] args) { yh(19); } /** * 它的两条斜边都是由数字1组成的,而其余的数则是等于它肩上的两个数之和。 * @param in */ public static void yh(int in){ int[] a = new int[in + 1]; int previous = 1; for (int i = 1; i <= in; i ++){ for (int j = 1; j <= i; j++){ int current = a[j]; a[j] = previous + current; previous = current; System.out.print(a[j] + " "); } System.out.println(); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报