Created
August 1, 2020 21:45
-
-
Save Ayeeta/429efba091e34aae7ca38341c83a3c83 to your computer and use it in GitHub Desktop.
Functions in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example with no args | |
fun exampleFunction(){ | |
println("This is an example of a function in Kotlin") | |
} | |
//Example with Args. Remember the data types are declared explicitly | |
fun exampleFunctionWithArgs(someString:String){ | |
println(someString) | |
} | |
/** | |
Example with return type | |
**/ | |
fun calculateArea(l:Int, w:Int):Int{ | |
val result = l * w | |
return result | |
} | |
//You can also assign your args like this | |
fun randomFun(msg: String = "This is so random"){ | |
println(msg) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment