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

 

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

Write a method that returns the sum of the numbers in the 'nums' array, but only include a number from 'nums' if the corresponding position in 'good' is 'true'. Note that the 'good' array might be shorter than the 'nums' array. If there is no corresponding location in the 'good' array, it can't have the value 'true' so you don't include that number. As a precondition, you may assume that the length of 'good' is less than or equal to the length of 'nums'.


test2022_09_12_SLHL_addIfGood([55], [false]) → 0
test2022_09_12_SLHL_addIfGood([55], [true]) → 55
test2022_09_12_SLHL_addIfGood([1, 2, 3, 4, 5, 6, 7], [false, false, false, true, false, true, false]) → 10

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

public int test2022_09_12_SLHL_addIfGood(int[] nums, boolean[] good) { }

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

Copyright Nick Parlante 2017 - privacy