In this tutorial, you shall learn how to write a program to find the sum of two given numbers in Kotlin.
Kotlin – Sum of two numbers
To find the sum of two numbers in Kotlin, you can use Arithmetic Addition Operator.
Program
In the following program, we take two numbers in x
, y
; find their sum, and print the output.
Main.kt
fun main() { print("Enter first number : ") val x = readLine()!!.toDouble() print("Enter second number : ") val y = readLine()!!.toDouble() val sum = x + y print("$x + $y is $sum") }
Output #1
Enter first number : 20 Enter second number : 40 20.0 + 40.0 is 60.0
Output #2
Enter first number : 2.53 Enter second number : 1.04 2.53 + 1.04 is 3.57
ADVERTISEMENT
Related Tutorials
Conclusion
In this Kotlin Tutorial, we learned how to find the sum of two numbers using Addition Operator.