-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoding Exercise 24 - Flour Pack Problem
More file actions
38 lines (36 loc) · 1.08 KB
/
Coding Exercise 24 - Flour Pack Problem
File metadata and controls
38 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class FlourPacker {
public static boolean canPack(int bigCount, int smallCount, int goal) {
boolean result = false;
if (bigCount < 0 || smallCount < 0 || goal < 0) {
return result;
}
if ((bigCount * 5) + (smallCount) >= goal) {
result = true;
while (goal > 0) {
if (goal >= 5) {
if(bigCount >= 1) {
goal -= 5;
bigCount--;
}
else if (smallCount >= goal) {
goal = 0;
return true;
} else {
return false;
}
}
else if (goal < 5) {
if (smallCount >= goal) {
goal = 0;
return true;
} else {
return false;
}
}
}
return result;
} else {
return false;
}
}
}