-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]]"

3
  • no its unfortunately not working ... type mismatch... Commented Jun 7, 2014 at 11:48
  • Ah, sorry. Probably this will help: stackoverflow.com/questions/2381908 Commented Jun 7, 2014 at 11:51
  • i cant manage it somehow i cant get it right !! Commented Jun 7, 2014 at 12:06

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

some thing like that : var ScoreMatrix: Array[Array[Int]] = new Array.ofDim[Int](5, 20)
Yes but without the "new" since the brackets already call the apply method.
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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.