Friday, November 8, 2019

How to Kotlin Program to Add Two Integers

In this program to Add Two Integers, similar to Java, two integers 10 and 20 are stored in the first and second integer variables, respectively. Not required: Int in the variable declaration, Kotlin automatically assigns a type (in this case, Int).
How to Kotlin Program to Add Two Integers

Then the first and second are added with the + operator and its results are stored in a different total variable.
fun main(args: Array<String>) {
    val first: Int = 10
    val second: Int = 20
    val sum = first + second
    println("The sum is: $sum")
}
When you run the program, the output will be:
The sum is: 30

No comments:

Post a Comment