Add Two Number Program

fun main(args: Array<String>) {
    var a=0 //1
    var b=0 //2
    println("Enter Two Integer Number")//3
    a = readLine()?.toInt()!! //4
    b = readLine()?.toInt()!!//5

    val sum = a+b//6
    println("Sum of Two Numbers are $a+$b=$sum")//7

}

Explanation of Program
1 We take one variable with name a and intial value is 0
2 We take second variable with name b and intial value is 0
3 Print Message for user so that he/she can enter two Integer number
4 Take user first input form command line and convert into Int and assign to a 
5 Take user second input form command line and convert into Int and assign to b
6 Add a and b values and assigned to variable sum
7 Print result to user on command line

Output
Enter Two Number
 29
 50
 Sum of Two Numbers are 29+50=79

Leave a Reply

Your email address will not be published. Required fields are marked *