How to use function in Scala

3 Answers

0 votes
object O {
    def function(): Unit = {       
          println("function()")  
    }  
    def main(args: Array[String]): Unit = {
       function()        
    }
}
     
      
      
      
/*
run:
      
function()
 
*/

 



answered Sep 9, 2020 by avibootz
0 votes
object O {
    def function() = {       
          var n = 346
          n  
    }  
    def main(args: Array[String]): Unit = {
        var result = function()
        
        println(result) 
    }
}
     
      
      
      
/*
run:
      
346
 
*/

 



answered Sep 9, 2020 by avibootz
0 votes
val add = (x: Int, y: Int) => x + y

println(add(11, 3))



  
/*
run:
   
14
   
*/

 



answered Oct 13, 2021 by avibootz
...