Kotlin: Function or Methods Example

  1. Simple Function. neither accepts nor return any variable or value
    fun helloWorld(){
      println("Hello World")
  2.  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){
  3. Functions that returns a value but takes no parameter
    fun getAuthorsName() : String {
     return "Olorunleke Opeyemi"
    fun getTodaysDate() : Date {
      return Date()
  4. 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"}



Edge Developer

Hello there, my name is Opeyemi Olorunleke. I am a Software Developer (majorly Android, GitHub Profile), Digital Marketer, Udemy Instructor, Technical Writer, Blogger & Webmaster.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button