1

I have the following code for reading 2 integers:

Array(N, Q) = readLine.split(" ").map(_.toInt)

For this, I am getting the following error:

error: value update is not a member of object Array

If I do

val Array(N, Q) = readLine.split(" ").map(_.toInt)

I get:

error: not found: value N

If I declare them before:

val N, Q

I get:

!error: '=' expected but ';' found.

So how can I read these integers at the same time?

bsky
  • 19,326
  • 49
  • 155
  • 270

1 Answers1

5

Don't capitalize the variable names.

scala> val Array(n, q) = Array(1, 2)
n: Int = 1
q: Int = 2

Scala pattern matching special-cases identifiers starting with capital letters.

Related questions:

Chris Martin
  • 30,334
  • 10
  • 78
  • 137