要求:打出九九乘法表
object test {def main(args: Array[String]): Unit = {for (i <- 1 to 9) { //外循环控制行数for (j <- 1 to i) { //内循环控制列数print(s"${j} * ${i} = ${i + j}\t")}println()}}
}
结果:
1 * 1 = 2
1 * 2 = 3 2 * 2 = 4
1 * 3 = 4 2 * 3 = 5 3 * 3 = 6
1 * 4 = 5 2 * 4 = 6 3 * 4 = 7 4 * 4 = 8
1 * 5 = 6 2 * 5 = 7 3 * 5 = 8 4 * 5 = 9 5 * 5 = 10
1 * 6 = 7 2 * 6 = 8 3 * 6 = 9 4 * 6 = 10 5 * 6 = 11 6 * 6 = 12
1 * 7 = 8 2 * 7 = 9 3 * 7 = 10 4 * 7 = 11 5 * 7 = 12 6 * 7 = 13 7 * 7 = 14
1 * 8 = 9 2 * 8 = 10 3 * 8 = 11 4 * 8 = 12 5 * 8 = 13 6 * 8 = 14 7 * 8 = 15 8 * 8 = 16
1 * 9 = 10 2 * 9 = 11 3 * 9 = 12 4 * 9 = 13 5 * 9 = 14 6 * 9 = 15 7 * 9 = 16 8 * 9 = 17 9 * 9 = 18