Let's print some fun statistics about some numbers!
Write a method named processNumbers
that accepts a single String
as input.
The String
will contain, on separate lines, integer values.
However, some lines may be blank, and other integers may have whitespace before or after.
Here's an example:
1
2
4
Process the String
line by line, using Kotlin's .toInt()
method to convert each line to an Int
value.
Print a report when you are done in the following format, in this case using the numbers shown above:
Count: 3
Sum: 7
Count Even: 2
Count Odd: 1
Average: 2.3
Note that you should format the average with a single decimal place.
You should examine how to use the Kotlin roundToInt
method and a bit of cleverness to accomplish this.
Stuck? You may find these lessons helpful: