仍在学习 Coursera Scala 课程的 hw1,我遇到了案例语句和元组的问题。
object Pascal {
def main(args: List[String]) = {
require((args length) == 2, "args length must equal 2")
println("calling pascal on " + (args head) + " and " + (args last))
pascal((args head) toInt, (args last) toInt)
}
def pascal(c: Int, r: Int): Int = {
require(((r >= 0) && (c >= 0))
&& (c > r + 1), "r and c must be >= 0 and c must be <= r + 1")
(c, r) match {
case (_, 0) => 1
case (0, _) => 1
case (1 + r, _) => 1 // error: value not found "+"
case (_, _) => pascal(r-1,c-1) + pascal(r-1,c-1)
}
}
}
请告诉我如何在 Scala 中编写代码:
case (1 + r, _) => 1