Scala Programming: Check whether two given integer values are in the range 20..50 inclusive
Scala Programming Basic Exercise-17 with Solution
Write a Scala program to check whether two given integer values are in the range 20..50 inclusive. Return true if 1 or other is in the said range otherwise false.
Sample Solution:
Scala Code:
object scala_basic {
def test(x: Int, y: Int): Boolean =
{
(x <= 20 || y >= 50) || (y <= 20 || x >= 50);
}
def main(args: Array[String]): Unit = {
println("Result: " + test(20, 84));
println("Result: " + test(14, 50));
println("Result: " + test(11, 45));
println("Result: " + test(25, 40));
}
}
Sample Output:
Result: true Result: true Result: true Result: false
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 three given integer values are in the range 20..50 inclusive. Return true if 1 or more of them are in the said range otherwise false.
Next: 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.
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