80.4k views
2 votes
Write a recursive method to form the sum of two positive integers a and b. Test your program by calling it from a main program that reads two integers from the keyboard and users your method to complete and print their sum, along with two numbers.

1 Answer

6 votes

Answer:

see the code snippet below writing in Kotlin Language

Step-by-step explanation:

fun main(args: Array<String>) {

sumOfNumbers()

}

fun sumOfNumbers(): Int{

var firstNum:Int

var secondNum:Int

println("Enter the value of first +ve Number")

firstNum= Integer.valueOf(readLine())

println("Enter the value of second +ve Number")

secondNum= Integer.valueOf(readLine())

var sum:Int= firstNum+secondNum

println("The sum of $firstNum and $secondNum is $sum")

return sum

}

User Diwatu
by
4.4k points