id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > da2022_11_10_sumUntilNeg
prev  |  next  |  chance

Write a method that returns the sum of all the numbers in array 'nums' up to but not including the first negative number. Array 'nums' can be any length, including length zero. The first number could be negative, in which case the sum is zero. All numbers could be non-negative, in which case the result should be the sum of all the numbers in the array. Look at the test data for examples.


da2022_11_10_sumUntilNeg([3, 7, 0, 2, 1, 4, 0, 7, -2, 4]) → 24
da2022_11_10_sumUntilNeg([]) → 0
da2022_11_10_sumUntilNeg([-5]) → 0

...Save, Compile, Run (ctrl-enter)

public int da2022_11_10_sumUntilNeg(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 230

Copyright Nick Parlante 2017 - privacy