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

 

orion.a.smith@gmail.com apcsa-loops > apcsaLoopsAddEveryOtherInclusive
prev  |  next  |  chance

Given two ints a and b, add every other number between a and b, inclusive of a and possibly of b if both are even or both are odd. So if a is 4 and b is 7, the result should be 10, the result of 4+6. For all inputs, a < b is a precondition (a is guaranteed to be less than b for all inputs).


apcsaLoopsAddEveryOtherInclusive(4, 7) → 10
apcsaLoopsAddEveryOtherInclusive(5, 8) → 12
apcsaLoopsAddEveryOtherInclusive(-10, -4) → -28

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

public int apcsaLoopsAddEveryOtherInclusive(int a, int b) { }

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

Copyright Nick Parlante 2017 - privacy