如何在scala中传递和返回数组

对于这个问题的基本程度,我深表歉意,但无论如何,这是我的第一个 Scala 项目,我试图做的就是将数组传递给函数并返回该函数。这是我所拥有的:

 def main(args: Array[String]): Unit = {
    // 9999 == infinite there should be no reason
    // that for the scope of this assignment there
    // there should be a value any bigger than this.
    var Nodes = 4;
    var infi = 9999;
    var pathTaken = Array(Nodes);
    var pathLens = Array(Nodes);
    var paths = Array(Nodes, Nodes);
    
    pathLens = lenInit(pathLens);
}

def pathLens(x : Array[4]): Unit = {
    x = (0, 0, 0, 0);
    return x;
} 

我知道这是非常基本和简单的,但我一生都是一个 C/python 人,到目前为止我一直在网上搜寻,但毫无结果。请帮助/指出我正确的方向,非常感谢!

回答

The best thing you can do is to stop and try to learn some basic scala syntax before trying exercises. Can I suggest you a couple great resources to learn Scala?

Book:

  • Get Programming with Scala

Video Tutorials:

  • Scala at Light Speed
  • Scala & Functional Programming for Beginners

Interactive Tutorials:

  • Scala exercises
  • Exercism.io

答案是 OOT,但我认为在这种情况下值得向这些资源发出信号。


以上是如何在scala中传递和返回数组的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>