1 Star 0 Fork 0

CS-IMIS-23/20172306

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PascalTriangle.java 908 Bytes
一键复制 编辑 原始数据 按行查看 历史
package wek3;
import java.util.Scanner;
public class PascalTriangle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
CircularArrayQueue queue = new CircularArrayQueue();
int a, b, n;
System.out.println("输入杨辉三角的行号:");
n = scanner.nextInt();
queue.enqueue(0);
queue.enqueue(1);
System.out.println(1);//无论是多少行,第一行的数字只会是1
for (int i= 0;i<n-1;i++) {//从第二行开始控制每一行
queue.enqueue(0);
int m =1;
while (m<queue .size() ){
a = (int) queue.first();
queue.dequeue();
b = (int) queue.first();
int c = a + b;
queue.enqueue(c);
System.out.print(c+" ");
m++;
}
System.out.println();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/20172306.git
git@gitee.com:CS-IMIS-23/20172306.git
CS-IMIS-23
20172306
20172306
master

搜索帮助