Scala Programming: Check two given integers whether either of them is in the range 100..200 inclusive
Scala Programming Basic Exercise-15 with Solution
Write a Scala program to check two given integers whether either of them is in the range 100..200 inclusive.
Sample Solution:
Scala Code:
object scala_basic {
def test(x: Int, y: Int): Boolean =
{
(x >= 100 && x <= 200) || (y >= 100 && y <= 200);
}
def main(args: Array[String]): Unit = {
println("Result: " + test(100, 199));
println("Result: " + test(250, 300));
println("Result: " + test(105, 190));
}
}
Sample Output:
Result: true Result: false Result: true
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 one of the given temperatures is less than 0 and the other is greater than 100.
Next: 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.
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