蓝桥网试题 java 基础练习 杨辉三角形

-----------------------------------------------------------

-----------------------------------------------------------

算法

 1 import java.util.*;
 2 public class Main {
 3     public static void main(String[] args) {
 4         int n = new Scanner(System.in).nextInt();
 5         int[] a = null;
 6         System.out.println(1);
 7         for(int i=2;i<=n;i++){
 8             int[] s = new int[i];
 9             s[0] =s[i-1] = 1;
10             System.out.print("1 ");
11             for(int j=1;j<=i-2;j++){
12                 s[j] = a[j-1]+a[j];
13                 System.out.print(s[j]+" ");
14             }
15             System.out.println("1");
16             a = s;
17         }
18     }
19 }

 

 

 

 

 

 

posted @ 2016-11-16 11:04  Luking  阅读(1080)  评论(0编辑  收藏  举报