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

 

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

Write a method that returns the sum of all the integers from 'low' up to and including 'high'. As preconditions you may assume that 'low' is less than or equal to 'high' and that the sum will not exceed the maximum value that can be stored in an integer. For example, if 'low' is -2 and 'high' is 4 you would return a 7 since (-2)+(-1)+(0)+(1)+(2)+(3)+(4) = 7. Look at the test data for other examples.


test2023_11_02_APP1SLHL_sumFromTo(1, 500) → 125250
test2023_11_02_APP1SLHL_sumFromTo(7, 10) → 34
test2023_11_02_APP1SLHL_sumFromTo(43, 77) → 2100

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

public int test2023_11_02_APP1SLHL_sumFromTo(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: 215

Copyright Nick Parlante 2017 - privacy