X1625: Sum elements in the array

Write the method int sumBeforeNegative(int[] nums) in Java that returns the sum of the elements in the array nums up till the first negative number.

Examples:

sumBeforeNegative({51,9,10}) -> 70
sumBeforeNegative({51,9,-10}) -> 60
sumBeforeNegative({-51,-9,-10}) -> 0

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.