1. 计算级数
import scala.io.StdIn.readLine
object test1 {
def main(args: Array[String]): Unit = {
val q = readLine("请输入一个大于0的数:").toDouble
val result = calculateSum(q)
println(s"Sn=$result")
}
def calculateSum(q: Double): Double = {
var n = 1.0
var sum = 0.0
while (sum < q) {
sum += (n+1) / n
n += 1
}
sum
}
}