Skip to main content

Parameterized Function Example Kotlin Program

1 min read Updated June 30, 2026
Share:
On this page (6sections)

Definition

A function is a block of code written to perform a task. A function may be a parameterized function or a parameter-less function. A function may return a value or it may not return a value. The name of a function starts with a small letter and then follows CamelCase.

Syntax

fun methodName(variable_name_1 : data_type, variable_name_2 : data_type) : return_data_type{
//Functionality code
}

Parameterized Function Example Program

fun main(args: Array < String > ) {
    val num1 = 11
    val num2 = 6
    
    //Calling function with 2 parameters num1 and num2 and assigning the result to num3
    val num3 = minValue(num1, num2) 

    //Printing result
    println("Minimum Value while comparison of num1 and num2 is = " + num3) 
}

//Function with Int return type
fun minValue(i: Int, j: Int): Int {
    val min: Int
    if (i > j) {
        min = j
    } else {
        min = i
    }
    return min
}

Sample Output

Minimum Value while comparison of num1 and num2 is = 6

How It Works

This Kotlin program demonstrates Parameterized Function Example. It first prepares the data it needs, then uses conditional logic to decide the result, and finally prints the output shown in the Sample Output above.

  1. Declare the variables that hold the program’s data.
  2. Use conditional statements to handle the different cases.
  3. Print the final result to the console so you can compare it with the sample output.

Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.

Frequently Asked Questions

What is Parameterized Function Example in Kotlin?
A function is a block of code written to perform a task.
How do I run this Kotlin example?
Run it in IntelliJ IDEA or Android Studio, or compile from the command line with `kotlinc file.kt -include-runtime -d file.jar` and run `java -jar file.jar`.
How can I practice Parameterized Function Example?
Copy the example into IntelliJ IDEA or Android Studio, run it, then change the values or add print statements to see how the output changes.

Related Tutorials

Search tutorials