我正在尝试运行该程序,但它告诉我找不到r。由于该方法在类中,因此如何调用该方法? (我假设错误是因为这个)

package pack

class Sud(val grid: List[List[Int]]) {

  def r(r: Int): List[Int] =
  //code
}

object Sud
{
  def main(args: Array[String])
  {

     val puzzle=new Sudoku(List(
          List(0, 0, 9, 0, 0, 7, 5, 0, 0),
        //rest of Sudoku puzzle created by repeating the above statement

          println(r(0)) //ERROR given here
  }
}

最佳答案

如评论中所述,在您的代码中r是一个类方法。因此,您需要实例化您的Class Sud才能调用该方法。

val inst: Sud = new Sud(puzzle)

println(inst.r(0))

10-05 23:42