Scala Programming: Check the largest number among three given integers
Scala Programming Basic Exercise-19 with Solution
Write a Scala program to check the largest number among three given integers.
Sample Solution:
Scala Code:
object scala_basic {
def test(x: Int, y: Int, z: Int): Int = {
List(x, y, z).max
}
def main(args: Array[String]): Unit = {
println("Result: " + test(1,2,3));
println("Result: " + test(1,3,2));
println("Result: " + test(1,1,1));
println("Result: " + test(1,2,2));
}
}
Sample Output:
Result: 3 Result: 3 Result: 1 Result: 2
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to check whether a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string.
Next: Write a Scala program to check which number is nearest to the value 100 among two given integers. Return 0 if the two numbers are equal.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework