0

In Java, I can write:

Double x = (x1 > x2)? x1:x2

But this doesn't seem to work in Scala, the following has an error:

var x = (x1 > x2)? x1:x2

I don't feel like writing a block of code for this in Scala:

var x = x2

if (x1 > x2 ) {
    x = x1
}

If there a cleaner way for such operation in Scala? Thanks!

Edamame
  • 23,718
  • 73
  • 186
  • 320

1 Answers1

8

According to this and this page you just use the regular if/else syntax:

var x = if(x1 > x2) x1 else x2
Raniz
  • 10,882
  • 1
  • 32
  • 64