Advertisement
Kotuara

Практика5.3

Dec 22nd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.TreeSet;
  4.  
  5. public class Main {
  6.  
  7.     public static class HeavyBox implements Comparable {
  8.         public int weight;
  9.  
  10.         public HeavyBox(int weight) {
  11.             this.weight = weight;
  12.         }
  13.  
  14.         public void Print() {
  15.             System.out.println(weight);
  16.         }
  17.  
  18.         @Override
  19.         public int compareTo(Object o) {
  20.             return 1;
  21.         }
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         TreeSet<HeavyBox> Tree = new TreeSet<>();
  26.         Tree.add(new HeavyBox(789));
  27.         Tree.add(new HeavyBox(237));
  28.         Tree.add(new HeavyBox(340));
  29.         Tree.add(new HeavyBox(300));
  30.         Tree.add(new HeavyBox(34));
  31.  
  32.         for (HeavyBox Box : Tree) {
  33.             Box.Print();
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement