打印出杨辉三角形(要求打印出10行如下图) 10
1个回答
展开全部
public class Test {
public static void main(String[] args){
int n = 10;
int[] last = new int[n];
for (int i = 0; i < n; ++i)
last[i] = 1;
int[] current = last.clone();
System.out.print("1\n1 1\n");
for (int i = 3; i <= n; ++i) {
for (int j = 1; j < i - 1; ++j) {
current[j] = last[j] + last[j - 1];
}
print(current, i);
int[] t = current;
current = last;
last = t;
}
}
static void print(int[] array, int n) {
for (int i = 0; i < n; ++i)
System.out.print(array[i] + " ");
System.out.println();
}
}
public static void main(String[] args){
int n = 10;
int[] last = new int[n];
for (int i = 0; i < n; ++i)
last[i] = 1;
int[] current = last.clone();
System.out.print("1\n1 1\n");
for (int i = 3; i <= n; ++i) {
for (int j = 1; j < i - 1; ++j) {
current[j] = last[j] + last[j - 1];
}
print(current, i);
int[] t = current;
current = last;
last = t;
}
}
static void print(int[] array, int n) {
for (int i = 0; i < n; ++i)
System.out.print(array[i] + " ");
System.out.println();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
东莞大凡
2024-08-11 广告
2024-08-11 广告
标定板认准大凡光学科技,专业生产研发厂家,专业从事光学影像测量仪,光学投影测量仪.光学三维测量仪,光学二维测量仪,光学二维测量仪,光学三维测量仪,光学二维测量仪.的研发生产销售。东莞市大凡光学科技有限公司创立于 2018 年,公司总部坐落于...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询