Q:

write a method that returns true if it is possible to make a package with goal kilos of rice

belongs to collection: java exercises (medium level )

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 true if it is possible to make a package with goal kilos of rice.

All Answers

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

public Boolean packageRice(Integer big, Integer small, Integer goal) {
boolean result = false;
if (big * 5 >= goal) {
    if (small >= goal % 5)
        result = true;
} else {
    if (small >= goal - big * 5) {
        result = true;
    }
}
return result;
}

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

total answers (1)

Write a method that checks if a binary tree is str... >>
<< Write a method that returns the Greatest Common Di...