V
V
Vladimir Rudometkin2019-12-12 19:52:59
Java
Vladimir Rudometkin, 2019-12-12 19:52:59

How to make a console addition calculator in Kotlin?

Good day, good community. Recently, for the sake of interest, I registered on the Hyperskill platform, and after some time I came across a puzzle with certain conditions. I will say right away that I do not have much programming experience and this is my first acquaintance with the Scanner library. By the way, you can only use it.
Task: After entering two numbers in one line , their sum should be displayed. If one number is entered, then it should be displayed. If nothing, then the answer is: the program should ignore it. Everything should continue until the /exit command is entered.
I wrapped everything in a loop, and then, no matter how I experimented with nextInt (), hasNext () and so on, everything goes astray. I've been fighting for the second day.
I/O example:
>17 9
26
>-2 5
3
>
>7
7
>/exit
Bye!
I would be very grateful for any guidance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-12-12
@alshch

val arr = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
The array will contain both numbers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question