-1

I am trying to write my Java ode from in Scala and I think I need some help. my problem:

Java:

public static int[][] ScoreMatrix = new int[5][20];

Scala:

var ScoreMatrix: Array[Array[Int]] = new Array[Array[Int]](5, 20)

It's not working, don't know why?

Error "too many arguments for constructor Array(_length:int)Array[Array[Int]]"

some some
  • 528
  • 7
  • 13
user3706354
  • 71
  • 1
  • 1
  • 5

2 Answers2

3

For initializing 5*20 2D int array you can use:

var ScoreMatrix: Array[Array[Int]] = Array.ofDim[Int](5, 20)

Your code doesn't work because the Array constructor has only one argument, which is the array length.

some some
  • 528
  • 7
  • 13
0

Consider also

Array.tabulate(5,20)( (x,y) => 1)

which instantiates a 5 by 20 array with Int: 1 (in general a function of x and y).

elm
  • 20,117
  • 14
  • 67
  • 113