0

Why this code is not working?

fun main(args: Array<String>) { val num1 : Int = readLine()!!.toInt() val num2 : Int = readLine()!!.toInt() print(num1 + num2) }

21st Jan 2019, 12:49 PM
Jaikaran Saini
Jaikaran Saini - avatar
5 Respuestas
+ 7
this is your updated code print statement should be like this way println("The sum is ${num1 + num2}") updated code:- fun main(args:Array<String>){ val num1: Int = readLine()!!.toInt() val num2: Int = readLine()!!.toInt() println("The sum is ${num1 + num2}") } You have tryed good just do add something like this way for easy understanding. fun main(args:Array<String>){ var num1: Int var num2: Int println("Enter the first number") num1 = readLine()!!.toInt() println("Enter the second number") num2 = readLine()!!.toInt() println("The sum is ${num1 + num2}") }
21st Jan 2019, 1:10 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Jaikaran Saini it's working properly try by giving proper input https://code.sololearn.com/cPMY0rgYGlJK/?ref=app
21st Jan 2019, 4:34 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Sorry but your updated code is also not working. It says Java.lang.numberformatexception
21st Jan 2019, 4:06 PM
Jaikaran Saini
Jaikaran Saini - avatar
+ 1
No it's not really working I don't know if my complier is working properly or I have any problems in my mobile but it showing same problem
21st Jan 2019, 4:38 PM
Jaikaran Saini
Jaikaran Saini - avatar
+ 1
Please can help me?😢
21st Jan 2019, 4:54 PM
Jaikaran Saini
Jaikaran Saini - avatar