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

 

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

Write a method that returns one of three things: either the sum of a and b, the product of a and b, or -1 as an error code. Return the product if 'op' is the times symbol: *. Return the sum if 'op' is the plus symbol: +. Return the error code if 'op' is any other symbol, or if either of the numbers passed in are negative.


quiz2021_10_21_APSLHL_operation(5413, 34, "+") → 5447
quiz2021_10_21_APSLHL_operation(-1, 23, "*") → -1
quiz2021_10_21_APSLHL_operation(-5, -5, "+") → -1

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

public int quiz2021_10_21_APSLHL_operation(int a, int b, String op) { }

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