Advertisement
mehedi2022

Tuples_Exercise

Sep 23rd, 2022
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.34 KB | None | 0 0
  1. //Exercise: Imagine you're working on an application where you track all your expenses. You need to represent an expense that consists of a name and a cost – for example, a 5$ meal at McDonald's. How would you represent it in Scala?
  2.  
  3. val meal = ("McDonald's" , 5)
  4. val name = meal._1
  5. val cost = meal._2
  6. println (s"A $cost$$ meal at $name.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement