Splitting with spaces

Report a typo

Write a program that takes one string and the number of substrings to split it. The program should split the string into substrings using any number of spaces (1 or more) as a separator.

Input: string: String, n: Int

Output: resulting n substrings, each on a new line.

Sample Input 1:

This   is a      text with   many     spaces
0

Sample Output 1:

This
is
a
text
with
many
spaces

Sample Input 2:

Lorem    ipsum dolor sit, amet,    consectetur
3

Sample Output 2:

Lorem
ipsum
dolor sit, amet,    consectetur
Write a program in Kotlin
fun main() {
val string = readLine()!!
val n = readLine()!!.toInt()

}
___

Create a free account to access the full topic