練習目的:加強對 for 的用法
顯示結果如圖:
綀習看看吧!
範例程式:
/** * @param args */ public static void main(String[] args) { System.out.print(" "); for (int i = 1; i <= 9; i++) { System.out.printf(" %d", i); } System.out.println(); System.out.println("--+---------------------------"); for (int i = 1; i <= 9; i++) { System.out.printf(" %d|", i); for (int j = 1; j <= 9; j++) { int x = i * j; if(x < 10){ System.out.printf(" %d ", x); }else{ System.out.printf(" %d", x); } } System.out.println(); } }
其它文章
沒有留言:
張貼留言