打印九九乘法表
①
1 package struct; 2 3 public class ForDemo04 { 4 public static void main(String[] args) { 5 /* 6 1 * 1 = 1 7 1 * 2 = 2 2 * 2 = 4 8 1 * 3 = 3 2 * 3 = 6 9 1 * 4 = 4 2 * 4 = 8 10 1 * 5 = 5 2 * 5 = 10 11 1 * 6 = 6 2 * 6 = 12 12 1 * 7 = 7 2 * 7 = 14 13 1 * 8 = 8 2 * 8 = 16 14 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 15 */ 16 for (int i = 1; i<= 9 ; i++) {// 第二个数 17 for (int j = 1; j <= 9; j++) { //第一个数 18 System.out.print(j + " * " + i + " = " + ( j * i) + "\t"); 19 } 20 System.out.println(); 21 } 22 23 } 24 } 25 /*①先打印第二列 26 * ②再把固定的1用一个循环包起来 27 * ③去掉重复项i<=j 28 * ④调整样式 29 * */
②
1 package struct; 2 3 public class ForDemo04 { 4 public static void main(String[] args) { 5 /* 6 1 * 1 = 1 7 1 * 2 = 2 2 * 2 = 4 8 1 * 3 = 3 2 * 3 = 6 9 1 * 4 = 4 2 * 4 = 8 10 1 * 5 = 5 2 * 5 = 10 11 1 * 6 = 6 2 * 6 = 12 12 1 * 7 = 7 2 * 7 = 14 13 1 * 8 = 8 2 * 8 = 16 14 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 15 */ 16 for (int i = 1; i<=9 ; i++) {// 第二个数 17 for (int j = 9; j >= i; j--) { //第一个数 18 System.out.print(j + " * " + i + " = " + ( j * i) + "\t"); 19 } 20 System.out.println(); 21 } 22 } 23 } 24 /*①先打印第二列 25 * ②再把固定的1用一个循环包起来 26 * ③去掉重复项i<=j 27 * ④调整样式 28 * */
③
1 package struct; 2 3 public class ForDemo04 { 4 public static void main(String[] args) { 5 /* 6 1 * 1 = 1 7 1 * 2 = 2 2 * 2 = 4 8 1 * 3 = 3 2 * 3 = 6 9 1 * 4 = 4 2 * 4 = 8 10 1 * 5 = 5 2 * 5 = 10 11 1 * 6 = 6 2 * 6 = 12 12 1 * 7 = 7 2 * 7 = 14 13 1 * 8 = 8 2 * 8 = 16 14 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 15 */ 16 for (int i = 1; i<=9 ; i++) {// 第二个数 17 for (int j = 1; j <= i; j++) { //第一个数 18 System.out.print(j + " * " + i + " = " + ( j * i) + "\t"); 19 } 20 System.out.println(); 21 } 22 } 23 } 24 /*①先打印第二列 25 * ②再把固定的1用一个循环包起来 26 * ③去掉重复项i<=j 27 * ④调整样式 28 * */