Scala - Map class (Mapping month numbers to names and vice versa) Code Example

The code for Map class (Mapping month numbers to names and vice versa)

object MyClass {
    def main(args: Array[String]) {
        val months_Num2Name = Map(
          1  -> "Jan",
          2  -> "Feb",
          3  -> "Mar",
          4  -> "Apr",
          5  -> "May",
          6  -> "Jun",
          7  -> "Jul",
          8  -> "Aug",
          9  -> "Sep",
          10 -> "Oct",
          11 -> "Nov",
          12 -> "Dec"
        )
        
        val months_Name2Num = Map(
          "Jan" -> 1,
          "Feb" -> 2,
          "Mar" -> 3,
          "Apr" -> 4,
          "May" -> 5,
          "Jun" -> 6,
          "Jul" -> 7,
          "Aug" -> 8,
          "Sep" -> 9,
          "Oct" -> 10,
          "Nov" -> 11,
          "Dec" -> 12
        )
        
        println(months_Num2Name(8))
        println(months_Name2Num("Dec"))
    }
}

/*
Output:
Aug
12
*/
Code by IncludeHelp, on August 15, 2022 22:58

Comments and Discussions!





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.