ソース
1 public Yanghui3jiao() { 2 List<String[]> rowList = new ArrayList<String[]>(); 3 List<String[]> newList = new ArrayList<String[]>(); 4 for (int i = 22; i > 0; i--) { 5 String str[] = new String[i]; 6 for (int j = 0; j < str.length; j++) { 7 if (j == 0 || j == str.length - 1) { 8 str[j] = "1"; 9 } else { 10 str[j] = "0"; 11 } 12 } 13 rowList.add(str); 14 } 15 16 String tmp[] = null; 17 18 for (int i = rowList.size() - 1; i > 0; i--) { 19 String str[] = rowList.get(i); 20 if (tmp != null) { 21 for (int x = 1; x < str.length - 1; x++) { 22 str[x] = String.valueOf((Integer.valueOf(tmp[x - 1]) + Integer.valueOf(tmp[x]))); 23 } 24 } 25 newList.add(str); 26 27 for (int o = 1; o < (rowList.size() - str.length); o++) { 28 System.out.print(" "); 29 } 30 31 for (int j = 0; j < str.length; j++) { 32 System.out.print(str[j] + " "); 33 } 34 System.out.println(""); 35 if (str.length != 1) { 36 tmp = str; 37 } 38 } 39 }