Kotlinlearncs.online LogoJava
Return to List

Homework: Double Array Range and Sum String

Created By: CEO
/ Version: 2023.8.0

Let's compute a few summary statistics on a dataset. Create a method named summarizeValues that accepts a non-empty DoubleArray.

Compute the mean and the range of the dataset and return a String in the following format:

Mean: <mean>
Range: <range>

Where <mean> and <range> are the mean and range of the dataset computed by your method.

Round the values to 2 decimal points using a method round which accepts a Double value. For example, round(3.33542) would return 3.34.

Given the array {1.0, 2.0, 4.0}, your method should return:

Mean: 2.33
Range: 3.0

(Note that Kotlin's multi-line string literal will not work correctly for this problem, so you'll need to insert the newline manually.)

Related Lessons

Stuck? You may find these lessons helpful: