杭电acm2032杨辉三角
2016-05-10 16:31
302 查看
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
2 3
1
1 1
1
1 1
1 2 1
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
2 3
1
1 1
1
1 1
1 2 1
import java.util.Scanner; public class Main { public static void print(int array[][]) { for(int i=1;i<=array.length - 1;i++) { for(int j=0;j<i;j++) { if(j==0 || j==array[i].length-1) { array[i][j]=1; }else{ array[i][j]=array[i-1][j-1]+array[i-1][j]; } if(j != 0) System.out.print(" "); System.out.print(array[i][j]); } System.out.println(); } System.out.println(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int repeat=sc.nextInt(); int array[][] =new int [repeat + 1][2 * repeat + 1]; print(array); } } }
相关文章推荐
- 汇编---水仙花数算法
- ural 1018 二*苹果树
- sql server 2008R2中的事务语句控制
- eclispe使用外部tomcat总结
- HeidiSQL无法连接Myql
- 工作记录--更新内核
- 1694: Primorial vs LCM 数论
- 模板的编译
- 开始写博客
- 基于多步迭代算法的数字预失真技术
- Xcode无证书打IPA包
- 流量监控工具类
- 正则去掉html中间的php代码
- Max Script|控制摄像机
- Android之使用Pull解析Xml数据
- hdu2509
- 常用Cocoa框架概览
- [LeetCode]题解(python):152-Maximum Product Subarray
- leetcode 336. Palindrome Pairs
- 笔记2