Apr
09
How to find the largest number in a given list of integers in Scala using reduceLeft
Hey there! Welcome to ClearUrDoubt.com. In this post, we will look at a Scala program to find the largest number in a given list of integers using reduceLeft. Let’s look at the program:
1 2 3 4 5 6 7 8 9 10 11 12 |
package com.clearurdoubt.practice object FindMax extends App { val l = List(1,-5,10,3,9) val max = l.reduceLeft( (a, b) => if(a > b) a else b ) println("Maximum number in (1,-5,10,3,9): " + max) } |
Output: Happy learning. Please leave a reply Read more