我刚开始学习scala。尝试实现递归函数时,我在 Eclipse 中收到错误“非法开始简单表达式”:
def foo(total: Int, nums: List[Int]):
if(total % nums.sorted.head != 0)
0
else
recur(total, nums.sorted.reverse, 0)
def recur(total: Int, nums: List[Int], index: Int): Int =
var sum = 0 // ***** This line complained "illegal start of simple expression"
// ... other codes unrelated to the question. A return value is included.
谁能告诉我在(递归)函数中定义变量时我做错了什么?我在网上进行了搜索,但无法解释此错误。