October 2018
Intermediate to advanced
370 pages
9h 15m
English
Functions can receive one or more parameters as arguments:
fun hello(message : String) : Unit { println("Hello from $message") } fun main(args: Array<String>) { hello("Kotlin") }
The hello function takes a string variable as a parameter. When the hello function is called from main, a string value is passed to that function.
If the function takes more than one parameter, all parameters are separated with a comma (,). Here is another example of writing a function that takes two parameters:
fun add(a : Int, b : Int) { println("Result of $a + $b is ${a+b}")}fun main (args: Array<String>){ add(4,5)}
In a function declaration, variables cannot be declared with the val or var keywords, and the data type must be specified ...
Read now
Unlock full access