Q:

write a method that returns the minimum number of small bags necessary to package goal kilos of rice

0

Provided that you have a given number of small rice bags (1 kilo each) and big rice bags (5 kilos each), write a method that returns the minimum number of small bags necessary to package goal kilos of rice. Return -1 if it is not possible to package the required rice amount with the bags provided.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public Integer getNumberSmallBags(Integer big, Integer small, Integer goal) {
int result = -1;
if (big * 5 >= goal) {
    if (small >= goal % 5)
        result = goal % 5;
} else {
    if (small >= goal - big * 5) {
        result = goal - big * 5;
    }
}
return result;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now