1. Introduction
In this article, we are going to present a Kotlin program to add two integer numbers. The program will display the sum result on the screen at the end.
2. Example: Add Two Integer Numbers in Kotlin
The output will be:
In this example, we declared two variables a
and b
with assigned values 21
and 9
. Note that the explicit determination of the variable's type is not mandatory in Kotlin. The :Int
statement could be skipped, then Kotlin automatically evaluates a type.
Values stored in a
and b
variable are added using the +
operator. The result of this operation is sored in the sum
variable.
In the next step, we used println(...)
function to print the sum
on the screen.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}