Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1.  
  2. public class BoxesOfBooks {
  3.  
  4.  
  5. public static int boxes (int []weights, int maxWeight) {
  6. int tot=0;
  7. int weightleft=maxWeight;
  8. for (int i=0; i<weights.length; i++) {
  9. //System.out.println(weightleft);
  10. if (weights[i]<=weightleft) {
  11. weightleft=weightleft-weights[i];
  12. }
  13. else if (weights[i]>weightleft) {
  14. tot++;
  15. weightleft=10;
  16. weightleft=weightleft-weights[i];
  17. }
  18.  
  19.  
  20. }
  21. return tot+1;
  22.  
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement