@Test public void for_5_5() { for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { while (i >= j) { System.out.print(j + "x" + i + "=" + i * j + " "); if (i == j) { System.out.println(); } break;//中断当前的for循环体与continue有区别 } } } }
方法2:
/** * 输出9 x 9乘法表 * 小于等于的处理 */ @Test public void for_9x9(){ for (int i=1;i<=9;i++){ for (int k=1;k<=i;k++){//小于等于 System.out.print(k + "x" + i + "=" + i * k + " "); } System.out.println(); } }