What's the capital?

Report a typo

We have the Map of capitals by country names in the scope:

val capitals: Map[String, String] = Map(
  "France" -> "Paris", 
  "Japan" -> "Tokyo",
  ...
)

We would like to get a capital by the name of the country. Rewrite the code to avoid possible runtime errors. If the value doesn't exist in the Map, print The capital doesn't exist or is not listed.

Sample Input 1:

France

Sample Output 1:

Paris
Write a program in Scala 3
def getCapital(country: String): String =
capitals(country)
___

Create a free account to access the full topic