Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. public static void main(String[] args)
  2.     {
  3.         Scanner scanner = new Scanner(System.in);
  4. //Правиш арей листове за всяка от кутиите
  5.         ArrayList<Integer> box1 = new ArrayList<>();
  6.         ArrayList<Integer> box2 = new ArrayList<>();
  7.         //пълниш първата кутия с първите 3 елемента
  8.         box1.add(scanner.nextInt());
  9.         box1.add(scanner.nextInt());
  10.         box1.add(scanner.nextInt());
  11.         //пълниш втората кутия с първите 3 елемента
  12.         box2.add(scanner.nextInt());
  13.         box2.add(scanner.nextInt());
  14.         box2.add(scanner.nextInt());
  15.  
  16.         //с помоща на метод от Collections framework сортираш двата листа за да се подредят елементите по големина
  17.         Collections.sort(box1);
  18.         Collections.sort(box2);
  19.  
  20.         //задаваш вече подредените стойности като страни на кутия
  21.         int x1 = box1.get(0);
  22.         int y1 = box1.get(1);
  23.         int z1 = box1.get(2);
  24.         int x2 = box2.get(0);
  25.         int y2 = box2.get(1);
  26.         int z2 = box2.get(2);
  27.  
  28.         //смяташ обема на всяка от кутиите
  29.         int area1 = x1 * y1 * z1;
  30.         int area2 = x2 * y2 * z2;
  31.  
  32.         //логиката която вече си въртял за определяне коя кутия е по-голяма
  33.         if (area1 == area2 && x1 + y1 + z1 == x2 + y2 + z2)
  34.         {
  35.             System.out.println("Box 1 = Box 2");
  36.         }
  37.         else if (area1 >= area2 && (x1 > x2 && y1 >= y2 && z1 >= z2) || (x1 >= x2 && y1 >= y2 && z1 > z2) || (x1 >=
  38.                 x2 && y1 > y2 && z1 >= z2))
  39.         {
  40.             System.out.println("Box 1 > Box 2");
  41.         }
  42.         else if (area2 >= area1 && (x2 > x1 && y2 >= y1 && z2 >= z1) || (x2 >= x1 && y2 >= y1 && z2 > z1) || (x2 >=
  43.                 x1 && y2 > y1 && z2 >= z1))
  44.         {
  45.             System.out.println("Box 1 < Box 2");
  46.         }
  47.         else
  48.         {
  49.             System.out.println("Incomparable");
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement