Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a static method namednegativeSum()that accepts a string of text as a parameter from the standard console input stream.Assume that the text is a series

Write a static method namednegativeSum()that accepts a string of text as a parameter from the standard console input stream.Assume that the text is a series of integers, and determine whether or not the cumulative sum starting from the first number is ever negative.The method should produce a message indicating whether or not a negative sum is possible and it should returntrueif a negative sum can be reached and false if it can't be reached.For example, if the string contains the following text,

"38 4 19 -27 -15 -3 4 19 38"

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.None of these sums is negative, so the method would produce the following message:

no negative sum

and would returnfalse.If the text is the following,

"14 7 -10 9 -18 -10 17 42 98"

the method finds that a negative sum is reached after adding 6 numbers together

(14 + 7 + -10 + 9 + -18 + -10)and that the sum is-8.It should report the following:

-8 after 6 steps

and should returntrue, indicating that a negative sum can be reached. (3pts)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions