Guest User

Untitled

a guest
Oct 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class Vehicle {
  2. public static void main(String[] args) {
  3. Integer[] outgoing = {2710,300,2500,2800,700};
  4. Integer[] returning = {2200,289,490};
  5. int l1=0,l2=0;
  6. Arrays.sort(outgoing, Collections.reverseOrder());
  7. Arrays.sort(returning);
  8. int range = 3000;
  9. int max = 0;
  10. int out = 0;
  11. int ret = 0;
  12. while(l1<outgoing.length && l2<returning.length) {
  13. int sum = outgoing[l1]+returning[l2];
  14. if (sum<=range && sum>max) {
  15. max = sum;
  16. out = outgoing[l1];
  17. ret = returning[l2];
  18. }
  19. if(sum>range) {
  20. l1++;
  21. } else {
  22. l2++;
  23. }
  24. }
  25. System.out.println(max);
  26. System.out.println(out);
  27. System.out.println(ret);
  28. }
  29. }
Add Comment
Please, Sign In to add comment