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

 

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

Write a method that will either add 'num1' and 'num2' or subtract them, depending on the value of 'add'. If 'add' is true, you add the two numbers. If 'add' is false you subtract them. If you end up subtracting the two numbers, you will subtract 'num2' from 'num1'. Look at the test data for examples. Remember: You may only use ONE return statement in a method! (My rule!)


test2023_09_08_APP1SLHL_addOrSubtract(5, 2, true) → 7
test2023_09_08_APP1SLHL_addOrSubtract(-9, 1, true) → -8
test2023_09_08_APP1SLHL_addOrSubtract(-15, 10, false) → -25

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

public int test2023_09_08_APP1SLHL_addOrSubtract(int num1, int num2, 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: 210

Copyright Nick Parlante 2017 - privacy