How to use method in Scala

3 Answers

0 votes
def add(x: Int, y: Int): Int = x + y

println(add(11, 3))



  
/*
run:
   
14
   
*/

 



answered Oct 13, 2021 by avibootz
0 votes
def addThenMultiply(x: Int, y: Int)(mul: Int): Int = (x + y) * mul

println(addThenMultiply(3, 4)(5)) 



  
/*
run:
   
35
   
*/

 



answered Oct 13, 2021 by avibootz
0 votes
def msquare(n: Double): String = {
  val square = n * n
  
  square.toString
}

println(msquare(3.14)) 



  
/*
run:
   
9.8596
   
*/

 



answered Oct 13, 2021 by avibootz

Related questions

...