码迷,mamicode.com
首页 > 其他好文 > 详细

杨辉三角

时间:2016-12-25 13:51:03      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:blog   ati   class   i++   rgs   string   pre   杨辉三角   sys   

 1 /**
 2  * 杨辉三角
 3  * @author chunzai
 4  *
 5  */
 6 public class Test1 {
 7     public static void main(String[] args) {
 8         int a[][] = new int[7][];
 9         for(int i=0;i<7;i++){
10             a[i] = new int[i+1];
11             for(int j=i;j<6;j++){
12                 System.out.print(" ");
13             }
14             for(int k=0;k<=i;k++){
15                 
16                 if(k==0||k==i){
17                     a[i][k] = 1;
18                     
19                 }else{
20                     a[i][k] = a[i-1][k]+a[i-1][k-1];
21                     
22                 }
23                 System.out.print(a[i][k]+" ");
24             }
25             System.out.println();
26         }
27     }
28 }

 

杨辉三角

标签:blog   ati   class   i++   rgs   string   pre   杨辉三角   sys   

原文地址:http://www.cnblogs.com/chunzai/p/6219359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!