object TestClass {
def main (args: Array[String]) {
println("Hello World");
val c = List (1,2,3,4,5,6,7,8,9,10)
println(findMax(c))
}
def findMax (tempratures: List[Int]) {
tempratures.foldLeft(Integer.MIN_VALUE) {Math.max}
}
}
显示的输出是
Hello World
()
为什么输出不是
Hello World
10
我在 IntelliJ 中这样做
最佳答案
这是最常见的 Scala 拼写错误之一。
您错过了 =
在你的方法结束时:
def findMax (tempratures: List[Int]) {
应该读:
def findMax (tempratures: List[Int]) = {
离开
=
off 表示您的方法返回 Unit
(没有)。
关于scala - 打印从 scala 函数返回的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906725/