Q:

Write a Scala program to compute the sum of the two given integer values. If the two values are the same, then return triples their sum

0

Write a Scala program to compute the sum of the two given integer values. If the two values are the same, then return triples their sum.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object scala_basic {
  def test(x:Int, y:Int) : Int =
    {
        if (x == y) (x + y) * 3 else x + y
    }
     
   def main(args: Array[String]): Unit = {
      println("Result: " + test(1, 2));
      println("Result: " + test(2, 2));
   }
}

Sample Output:

Result: 3
Result: 12

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now