标签:style int length first https i++ nbsp oid div
今天突然想温习一下Java的基础,想了想就写写杨辉三角吧
1 public class First 2 { 3 public static void main(String[] args) 4 { 5 int[][] Arr = new int[5][]; 6 for(int i = 0; i < Arr.length; i++) 7 { 8 Arr[i] = new int[i + 1]; 9 Arr[i][0] = 1; 10 Arr[i][i] = 1; 11 for(int j = 0; j < Arr[i].length - 1; j++) 12 if(j >= 1 && i > 1) 13 Arr[i][j] = Arr[i - 1][j - 1] + Arr[i - 1][j]; 14 } 15 for(int i = 0; i < Arr.length; i++) 16 { 17 for(int j = 0; j < Arr.length - Arr[i].length; j++) 18 System.out.print(" "); 19 for(int j = 0; j < Arr[i].length; j++) 20 { 21 System.out.print(Arr[i][j]); 22 System.out.print(" "); 23 } 24 System.out.println(); 25 } 26 } 27 }
作者:耑新新,发布于 博客园
转载请注明出处,欢迎邮件交流:zhuanxinxin@foxmail.com
标签:style int length first https i++ nbsp oid div
原文地址:http://www.cnblogs.com/Amedeo/p/7571565.html