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

 

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

Write a method that returns the sum of all the integers in the array 'toAdd', unless 'dbl' is true. If 'dbl' is true, ODD numbers count normally towards the sum, but EVEN numbers count double. For example, if the array contains [5, 6, 4] and 'dbl' is false, you would return 15 since 5+6+4=15. However, if 'dbl' was true you would return 25 since 5+2*6+2*4=25. As a precondition, you may assume that the array will not contain any negative numbers. Look at the test data for additional examples.


test2021_11_04_APSLHL_addArray([7, 12, 35], false) → 54
test2021_11_04_APSLHL_addArray([], false) → 0
test2021_11_04_APSLHL_addArray([9242, 325, 4578, 463, 34], true) → 28496

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

public int test2021_11_04_APSLHL_addArray(int[] toAdd, boolean dbl) { }

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

Copyright Nick Parlante 2017 - privacy