Scala Function: Exercises, Practice, Solutions
Scala Functions and Methods Exercises [ 10 exercises with solution ]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. Write a Scala function to calculate the factorial of a given number.
Click me to see the sample solution
2. Write a Scala function to check if a given number is prime.
Click me to see the sample solution
3. Write a Scala function to calculate the sum of digits in a given number.
Click me to see the sample solution
4. Write a Scala function to reverse a given string.
Click me to see the sample solution
5. Write a Scala function to check if a given string is a palindrome.
Click me to see the sample solution
6. Write a Scala function to find the maximum element in an array.
Click me to see the sample solution
7. Write a Scala function to calculate the power of a number.
Click me to see the sample solution
8. Write a Scala function to check if a given number is even.
Click me to see the sample solution
9. Write a Scala function to check if a given number is a perfect square.
Click me to see the sample solution
10. Write a Scala function to check if a given list is sorted in ascending order.
Click me to see the sample solution
More ...
Scala Code Editor:
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
Test your Python skills with w3resource's quiz
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics