本文主要是介绍scala案例-- 九九乘法表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
要求:打出九九乘法表
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
这篇关于scala案例-- 九九乘法表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!