logo Practice-It logo

runningSum

Language/Type: Java file processing Scanner
Author: Roy McElmurry

Write a static method called runningSum that accepts as a parameter a Scanner holding a sequence of real numbers and that outputs the running sum of the numbers followed by the maximum running sum. In other words, the nth number that you report should be the sum of the first n numbers in the Scanner and the maximum that you report should be the largest such value that you report. For example if the Scanner contains the following data:

3.25 4.5 -8.25 7.25 3.5 4.25 -6.5 5.25

your method should produce the following output:

running sum = 3.25 7.75 -0.5 6.75 10.25 14.5 8.0 13.25
max sum = 14.5

The first number reported is the same as the first number in the Scanner (3.25). The second number reported is the sum of the first two numbers in the Scanner (3.25 + 4.5). The third number reported is the sum of the first three numbers in the Scanner (3.25 + 4.5 + -8.25). And so on. The maximum of these values is 14.5, which is reported on the second line of output. You may assume that there is at least one number to read.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.