0

I am trying to read a multidimensional array line by line, as shown beneath:

var a = Array(MAX_N)(MAX_M)
for(i <- 1 to m) {
   a(i) = readLine.split(" ").map(_.toInt)
}

However, I am getting the error:

error: value update is not a member of Int

So, how can I read the array line by line?

Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
bsky
  • 19,326
  • 49
  • 155
  • 270
  • 1
    I'm not trying to be funny, but you're asking a lot of questions about _very_ basic parts of Scala. A quick run through one of the many Scala tutorials may well be a good investment of your time – The Archetypal Paul Dec 26 '15 at 16:56

1 Answers1

3

The main problem here is actually in your first line of code.

Array(MAX_N)(MAX_M) doesn't mean what you think it means.

The first part, Array(MAX_N), means "make an array of size 1 containing MAX_N", and then (MAX_M) means "return the MAX_M'th element of that array". So for example:

scala> Array(9)(0)
res1: Int = 9

To make a two-dimensional array, use Array.ofDim. See How to create and use a multi-dimensional array in Scala?

(There are more problems in your code after the first line. Perhaps someone else will point them out.)

Community
  • 1
  • 1
Seth Tisue
  • 29,985
  • 11
  • 82
  • 149