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

 

makeChocolateH


We want make a package of chocolate with the a specified number of ounces. We use small nuggets of chocolate (1 ounch each) and big bars (5 ounces each). Return the number of nuggets to use, assuming we always use big bars before nuggets. Return -1 if it can't be done. The input is (number of nuggets provided, number of big bars, ounces in package). makeChocolateH(4, 1, 9) means "Can I make a 9 ounce package if I have 4 nuggets and 1 big bar available?" The answer is yes: I need all 4 nuggets. makeChocolateH(4, 1, 10) has an answer of -1 because I can't make a 10 ounce package with that amount of chocolate.


makeChocolateH(4, 1, 9) → 4
makeChocolateH(4, 1, 10) → -1
makeChocolateH(4, 1, 7) → 2

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

public int makeChocolateH(int nuggets, int bars, int goal) { }

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

Copyright Nick Parlante 2017 - privacy