Advertisement
porteno

Q3

Dec 7th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class Q3 {
  2. public static void main(String[] args) {
  3.  
  4. }
  5.  
  6. public static void threeFlashLights(FlashLight[] arr, double total){
  7.  
  8. FlashLight flsh1 = arr[0], flsh2= arr[0], flsh3= arr[0];
  9. boolean runLoop = true;
  10. for (int i = 0; i < arr.length-2 && runLoop; i++) {
  11. flsh1 = arr[i];
  12. for (int j = i+1; j < arr.length-1 && runLoop ; j++) {
  13. flsh2 = arr[j];
  14. for (int k = j+1; k < arr.length && runLoop; k++) {
  15. flsh3 = arr[k];
  16. if(flsh1.getPrice() + flsh2.getPrice() + flsh3.getPrice() == total)
  17. runLoop = false;
  18. }
  19. }
  20. }
  21. if(!runLoop)
  22. System.out.println(flsh1.getModel() + " " + flsh2.getModel() + " " + flsh3.getModel());
  23. else
  24. System.out.println("nothing found");
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement