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

 

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

Write a method that returns the sum of all the integers in array 'nums' in all of the array indicies from 'low' to 'high' inclusive. As preconditions, you may assume that 'low' and 'high' are non-negative, but you may NOT assume that 'low'<='high'. If 'high'<'low' then the result is zero. If 'low' is greater than the last index in the array, also return zero. If 'high' is greater than the last index of the array, find the sum from 'low' all the way to the end of the array. Look at the test data for examples. You MAY solve this recursively, but recursion is NOT required.


feb_22_2019_APSLHL_sumBetween([5, 3, 7, 19, 1, 4, 22, 8, 13], 3, 4) → 20
feb_22_2019_APSLHL_sumBetween([5, 7, 1, 200, 50, 7, 3, 4, 9], 3, 5) → 257
feb_22_2019_APSLHL_sumBetween([8, 9, 2, 30], 1, 8) → 41

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

public int feb_22_2019_APSLHL_sumBetween(int[] nums, int low, int high) { }

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

Copyright Nick Parlante 2017 - privacy