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

 

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

Write a method that returns the sum of all the numbers in array 'nums' up to but not including the 'n'th negative number. Array 'nums' can be any length, including length zero. Each number could be positive, negative, or zero. All numbers are included in the sum up to, but not including, the 'n'th negative number. There could be fewer than 'n' negative numbers, in which case the result should be the sum of all the numbers in the array. Look at the test data for examples.


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

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

public int test2022_12_08_P1SLHL_sumUntilNthNeg(int[] nums, int n) { }

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: 240

Copyright Nick Parlante 2017 - privacy