Scala Programming: Check whether a given positive number is a multiple of 3 or a multiple of 7
Scala Programming Basic Exercise-11 with Solution
Write a Scala program to check whether a given positive number is a multiple of 3 or a multiple of 7.
Sample Solution:
Scala Code:
object scala_basic {
def test(n: Int): Boolean =
{
n % 3 == 0 || n % 7 == 0;
}
def main(args: Array[String]): Unit = {
println("Result: " + test(3));
println("Result: " + test(14));
println("Result: " + test(12));
println("Result: " + test(37));
}
}
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 create a new string with the last char added at the front and back of a given string of length 1 or more.
Next: Write a Scala program to create a new string taking the first 3 characters of a given string and return the string with the 3 characters added at both the front and back. If the given string length is less than 3, use whatever characters are there.
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