Summing up space-separated integers from a string

Report a typo

Given a string input with numbers separated by whitespaces, Generate a code in Kotlin that uses readln to read the data and converts each number to an integer. Then, determine the sum of these integers and output it. For example, if your string input is '2 4 6', convert those to integers and print the sum; in this case 12.

Sample Input 1:

1 3 5

Sample Output 1:

9

Sample Input 2:

2 4 6

Sample Output 2:

12
Write a program in Kotlin
// Importing necessary libraries
import java.util.Scanner

fun main(args: Array<String>) {
// Initialisation of a Scanner
val scanner = Scanner(System.`in`)

// TODO: Get input string line
// TODO: Use split to create an array
// TODO: Iterate over array to convert from String to Int and accumulate the sum
// TODO: Print the sum.
}

Create a free account to access the full topic