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

 

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

Write a method that accepts a non-empty array of integers. Find the sum of all the positive integers in the array. Also find the sum of all the negative integers in the array. Return whichever of these sums is farthest from zero. If they are both the same distance from zero, return zero.


fromZero([5, 7, 2, 1, -4, -6, 3]) → 18
fromZero([-5]) → -5
fromZero([0, 0, 0, 0]) → 0

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

public int fromZero(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: 350

Copyright Nick Parlante 2017 - privacy