MODULE 8 - Kotlin function

Pre – test:
What is functions? What are the different types of functions?

Assessment

1. Write the output of these two programs:

A.

1. fun main(args: Array<String>){

2. sum()

3. print("code after sum")

4. }

5. fun sum(){

6. var num1 =5

7. var num2 = 6

8. println("sum = "+(num1+num2))

9. }

Output:






B.

1. fun main(args: Array<String>){

2. val result = sum(5, 6)

3. print(result)

4. }

5. fun sum(number1: Int, number2:Int): Int{

6. val add = number1+number2

7. return add

8. }

Output:







Create a simple function which will take an integer as input and returns the square of it.​