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
}
}
标签:val,级数,Double,sum,calculateSum,result,计算,var
From: https://www.cnblogs.com/lin513/p/18001535