Scala 编写乘法表函数 - 从终端输入整数 (1-9)
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()
}
}
}
}```
原文地址: https://www.cveoy.top/t/topic/knt0 著作权归作者所有。请勿转载和采集!