import scala.io.StdIn

def multiplicationTable(num: Int): Unit = {
  for (i <- 1 to num) {
    for (j <- 1 to i) {
      print(s'$j * $i = ${i * j}	')
    }
    println()
  }
}

print("请输入一个整数(1—9): ")
val num = StdIn.readInt()
if (num >= 1 && num <= 9) {
  multiplicationTable(num)
} else {
  println("输入有误,请重新输入!")
}
Scala 实现 1-9 整数乘法表

原文地址: https://www.cveoy.top/t/topic/kntR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录