用For或While迴圈寫出99乘法表
阿新 • • 發佈:2022-02-27
1 package com.xl.struct; 2 3 public class ForDemo04 { 4 public static void main(String[] args) { 5 //1.我們先列印第一列,這個大家應該都會 6 //2.我們把固定的1再用一個迴圈包起來 7 //3.去掉重複項, i<=j 8 //4.調整樣式 9 for (int j = 1; j <= 9; j++) { 10 for (int i = 1; i <= j; i++) {11 System.out.print(j+"*"+i+"="+(j*i)+"\t"); 12 13 } 14 System.out.println(); 15 16 } 17 18 19 } 20 }
1 package com.xl.exercise; 2 3 public class WhileForDemo04 { 4 public static void main(String[] args) { 5 int i,j; 6 j=1;7 while (j<=9){ 8 i=1; 9 while (i<=j) { 10 System.out.print(i + "*" + j + "=" + i * j + "\t"); 11 i++; 12 } 13 j++; 14 System.out.println(""); 15 } 16 } 17 18 }