// 計算楊暉三角形 import java.io.*; public class a07a{ public static void main(String args[]) throws Exception { //程式進入點 String getbr; int i,j; int a,b;//a階到b階 int tmp; int pad; int cans; BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); while (true) { do { System.out.println("請寫出a階到b階之楊暉三角塔:"); System.out.print("請輸入a "); getbr = br.readLine(); if (getbr.equals("0")) //判斷結束 { System.out.println("結束!"); return; } a=Integer.parseInt(getbr);//取得A階 System.out.print("請輸入b "); getbr = br.readLine(); // if (getbr.equals("0")) //判斷結束,要拿掉啦!不然沒有第0階 // { // System.out.println("結束!"); // return; //} b=Integer.parseInt(getbr);//取得B階 } while (a<0 || b< 0||a>10||b>10); /********** 處理好a b的大小關係 ********/ if (a>b) { tmp=a; a=b; b=tmp; } for (i=a;i<=b;i=i+1){ { pad=(11-i-1)/2; //算出要補多少五個空白的磚塊 if ((pad*2+i+1)<11) System.out.print(" "); for (j=0;j