Given a space separated list of integers, sort the list in ascending order and output the sorted list with each number followed by a space. The program should be capable of sorting both positive and negative numbers.
Introduction to collections
Sorting a list of positive and negative integers
Report a typo
Sample Input 1:
3 -4 2 7 -1Sample Output 1:
-4 -1 2 3 7 Sample Input 2:
10 2 8 4 6Sample Output 2:
2 4 6 8 10 Write a program in Kotlin
import java.util.*
fun main(args: Array<String>) {
// Create a mutable list to store the input numbers
val numberList = mutableListOf<Int>()
// Use a scanner to read the user input
val scanner = Scanner(System.`in`)
// TODO: Extract the integers from the input and add them to the mutable list
// TODO: Sort the list in ascending order
// TODO: Iterate through the sorted list and print each number followed by a space.
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.