|NO.Z.00071|——————————|BigDataEnd|——|Java&循环结构.V10|——|Java.v10|双重for循环.v03|打印九九乘法表|
一、双重for循环打印九九乘法表
### --- 案例题目
~~~ ——> 使用双重for循环打印九九乘法表。

二、编程代码
### --- 编程代码
/*
使用双重for循环打印九九乘法表
*/
public class ForForTableTest {
public static void main(String[] args) {
// 1.使用外层for循环控制打印的行数,一共9行
outer:for(int i = 1; i <= 9; i++) {
// 2.使用内层for循环控制打印的列数,最多9列,规律是:与当前行所在的行数相等
for(int j = 1; j <= i; j++) {
// 3.使用两个循环变量来拼接等式
System.out.print(j + "*" + i + "=" + j*i + " ");
// 4.当打印完毕6*6 = 36后结束整个打印
if(6 == j) {
//break; // 主要用于跳出循环,但该关键字只能跳出当前所在的循环
break outer; // 表示可以跳出外层for循环
}
}
System.out.println();
}
}
}
三、编译打印
### --- 编译
C:\Users\Administrator\Desktop\project>javac ForForTableTest.java
### --- 打印输出
C:\Users\Administrator\Desktop\project>java ForForTableTest
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号