Tuesday, February 19, 2019

match case example in Scala

match case example in Scala



scala> def f1(x:Int):Unit = {
     | x match{
     | case 1 => println("One")
     | case 2 => println("Two")
     | case 3 => println("Three")
     | case 4 => println("Four")
     | case _ => println("Other Number")
     | }

     | }

f1: (x: Int)Unit

scala> f1(1)
One

scala> f1(2)
Two

scala> f1(_)
res2: Int => Unit = $$Lambda$1067/1853443923@2e1ba142

scala> f1(0)
Other Number

No comments:

Post a Comment

Python Challenges Program

Challenges program: program 1: #Input :ABAABBCA #Output: A4B3C1 str1="ABAABBCA" str2="" d={} for x in str1: d[x]=d...