Q:

Write a Scala program to find the largest and smallest number from a given list

0

Write a Scala program to find the largest and smallest number from a given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_List
{
def main(args: Array[String]): Unit = 
 {
   //Iterate over a list
   val nums = List(1, 3, 5, 7, 9, 11, 14, 12)
   println("Original list:")
   println(nums)   
   println("Largest number of the said list:")
   println(nums.max)
   println("Smallest number from the said list:")
   println(nums.min)
  }
}

Sample Output:

Original list:
List(1, 3, 5, 7, 9, 11, 14, 12)
Largest number of the said list:
14
Smallest number from the said list:
1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now