w3resource

Kotlin Lambda: Exercises, Practice, Solutions

Kotlin Lambda expressions and anonymous functions Exercises [ 14 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 Kotlin program that implements a lambda expression to multiply two numbers and return the result.

Click me to see the solution

2. Write a Kotlin program that implements a lambda expression to find the square of a number and return the result.

Click me to see the solution

3. Write a Kotlin program that implements a lambda expression to check if a number is even.

Click me to see the solution

4. Write a Kotlin program that implements a lambda expression to calculate the average of a list of numbers.

Click me to see the solution

5. Write a Kotlin program that implements a lambda expression to filter a list of strings. It returns only strings starting with the letter 'K'.

Click me to see the solution

6. Write a Kotlin program that implements a lambda expression to sort a list of integers in descending order.

Click me to see the solution

7. Write a Kotlin program that implements a lambda expression to convert a list of strings to uppercase.

Click me to see the solution

8. Write an anonymous Kotlin function to check if a string is a palindrome.

Click me to see the solution

9. Write an anonymous Kotlin function to calculate the factorial of a number.

Click me to see the solution

10. Write an anonymous Kotlin function to find the maximum element in an array.

Click me to see the solution

11. Write an anonymous Kotlin function to count the number of vowels in a string.

Click me to see the solution

12. Write an anonymous Kotlin function to calculate the sum of all odd numbers in a list.

Click me to see the solution

13. Write an anonymous Kotlin function to concatenate two strings and return the result.

Click me to see the solution

14. Write an anonymous Kotlin function to find the average of the squares of a list of numbers.

Click me to see the solution

More to Come !

* To run the code mouse over on Result panel and click on 'RERUN' button.*

Kotlin Editor:


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.