Scala - Variables in Matches Code Example

The code for Variables in Matches

import scala.util.Random

// Generate an integer number
val random_number = new Random().nextInt(100)

random_number match {
 case 21 => println("Got my luck number.")
 case number => println("The number is: " + number)
}

/*
Output:
The number is: 79
*/
Code by IncludeHelp, on August 7, 2022 17:46

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.