You must disable your AdBlock software in your browser to use this site.
Disable ad blocking for practiceit.cs.washington.edu, then refresh this page to continue.
It is easy to disable AdBlock for just one site while leaving it enabled for other sites.
Just click the "stop sign" icon in the top-right of your browser, then un-check the "Enabled for this site" checkbox.
Thank you for your understanding and helping us to keep Practice-It free of cost for all students to use.
If you are still seeing this message after disabling your ad blocker, try clearing your browser history and refreshing the page.
Also make sure you don't have any other ad-blocking software running outside of your browser, such as a HOSTS file or proxy.
If you are certain that you are not running AdBlock or any other ad-blocking software, but you are still seeing this message,
please Contact Us.
Write a method named negativeSum that accepts a Scanner as a parameter reading input from a file containing a series of integers, and determine whether the sum starting from the first number is ever negative. The method should print a message indicating whether a negative sum is possible and should return true if a negative sum can be reached and false if not. For example, if the file contains the following text, your method will consider the sum of just one number (38), the sum of the first two numbers (38 + 4), the sum of the first three numbers (38 + 4 + 19), and so on up to the sum of all of the numbers:
38 4 19 -27 -15 -3 4 19 38
None of these sums is negative, so the method would produce the following message and return false:
no negative sum
If the file instead contains the following numbers, the method finds that a negative sum of -8 is reached after adding 6 numbers together (14 + 7 + -10 + 9 + -18 + -10):
14 7 -10 9 -18 -10 17 42 98
It should output the following and return true, indicating that a negative sum can be reached: