Kotlin Methods Example
- Simple Function. neither accepts nor return any variable or value
fun helloWorld(){ println("Hello World") } - Function that takes a parameter but returns no value
fun stringFunction (text : String){ for (c in text){ println("$c ") //KOTLIN -> K O T L I N } } fun intFunction(int : Integer){ println(int) } - Functions that returns a value but takes no parameter
fun getAuthorsName() : String { return "Olorunleke Opeyemi" } fun getTodaysDate() : Date { return Date() } - Functions that accept a value and returns a value
class Example{ fun main(args: Array<String>) { println(evaluateInteger(21, 23)) } fun evaluateInteger (a : Int, b: Int) : String { return if (a>b) { "$a is greater than $b" } else if (a<b){ "$b is greater than $a" } else {"they are equal"} } }
Comments
Post a Comment