Kotlin Program:

- To Create a function to add 2 numbers

Example:

User Input: 2,3

Output: 5

import java.util.Scanner

fun sum(n1:Int,n2:Int):Int {
  return n1+n2
}

fun main(args: Array<String>) {
  print("Enter two numbers : ")
  val userInput = Scanner(System.`in`)
  var n1:Int = userInput.nextInt()
  var n2:Int = userInput.nextInt()

  print("Sum : ${sum(n1,n2)}")
}

Output:

  Enter two numbers : 7
  5
  Sum : 12
Program
basic
//function to add 2 numbers
fun sum(n1:Int, n2:Int):Int {
  return n1+n2;   //use add(+) operator
}

Since, function returns integer data type, so we declare Int with : just after the function

For devision (/), subtraction (-), multiplication (*), you can use their respective operators

Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.