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_SLHL_addOrSubtract
prev  |  next  |  chance

Write a method that finds the 'total' of all the numbers in the array 'nums' by either adding each number to the total or subtracting it from the total. You add the number if the Boolean value in array 'add' is "true" in the position that corresponds to the number in 'nums' array. If the Boolean value is "false" then subtract the number from the total. As a precondition you may assume that 'nums' and 'add' have the same number of elements. Note that the arrays could be empty, in which case you simply return zero.


feb_22_2019_SLHL_addOrSubtract([92, 42, 48, 0, 0, 2], [true, false, false, true, false, true]) → 4
feb_22_2019_SLHL_addOrSubtract([92, 42, 48, 0, 0, 2], [false, false, true, true, false, true]) → -84
feb_22_2019_SLHL_addOrSubtract([6, 5, 4, 3, 2, 1], [true, false, true, false, false, false]) → -1

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

public int feb_22_2019_SLHL_addOrSubtract(int[] nums, boolean[] add) { }

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