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).
Then the first and second are added with the + operator and its results are stored in a different total variable.
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>) {When you run the program, the output will be:
val first: Int = 10
val second: Int = 20
val sum = first + second
println("The sum is: $sum")
}
The sum is: 30
No comments:
Post a Comment