import scala.io.StdIn

object MultiplicationTable {
  def main(args: Array[String]): Unit = {
    println('请输入一个整数(1-9):')
    val num = StdIn.readInt()
    if (num < 1 || num > 9) {
      println('输入的数字不合法!')
    } else {
      for (i <- 1 to num) {
        for (j <- 1 to i) {
          print(s'$j * $i = ${i * j}	')
        }
        println()
      }
    }
  }
}```
Scala 编写乘法表函数 - 从终端输入整数 (1-9)

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

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