Kotlinlearncs.online LogoJava
Return to List

Solve: Print Number Summary

Imported By: Geoffrey Challen
/ Version: 2022.7.0

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:



Process the String line by line, using Integer.parseInt 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 Math.round method and a bit of cleverness to accomplish this.

Related Lessons

Stuck? You may find these lessons helpful: