Fork me on GitHub

Introduction to Lambda Expressions with SARL

Note If you don’t know how to solve an problem, or what is the function to be used, you could search on Internet for the answer using the API of the Java programming language. Indeed, since SARL is fully compatible with the Java API, you could use all the types or functions that are defined in this Java API.

1. Exercise 1

25
48

Answer

2. Exercise 2

Double the number of 15 = 30
Triple the number of 15 = 45
Quadruple the number of 15 = 60
Quintuple the number 15 = 75

Answer

Answer #2 is:


class Solution2 {
	static def computeLambda(n : int) : (int) => int {
		[it * n]
	}
	static def main {
		var result = computeLambda(2)
		println("Double the number of 15 =" + result.apply(15))
		result = computeLambda(3)
		println("Triple the number of 15 =" + result.apply(15))
		result = computeLambda(4)
		println("Quadruple the number of 15 =" + result.apply(15))
		result = computeLambda(5)
		println("Quintuple the number of 15 =" + result.apply(15))
	}
}

</div>

3. Exercise 3

Answer

4. Exercise 4

Answer

5. Exercise 5

Answer

6. Exercise 6

Answer

7. Exercise 7

Answer

8. Exercise 8

2020-01-15 09:03:32.744178
2020
1
15
09:03:32.744178

Answer

9. Exercise 9

26587 : true
4.2365 : true
-12547 : false
00 : true
Z001 : false
001 : true
-16.4 : true
-24587.11 : true

Answer

10. Exercise 10

Answer