Advertisement
JeffGrigg

ThreesAndFivesSets

Oct 9th, 2020
2,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.45 KB | None | 0 0
  1. import java.util.TreeSet;
  2.  
  3. public class ThreesAndFivesSets {
  4.  
  5.     private static final int LIMIT = 10_000_000;   // = 10^7
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         final TreeSet<Integer> integers = new TreeSet<>();
  10.         for (int i = 3; i <= LIMIT; i+= 3) {
  11.             integers.add(i);
  12.         }
  13.         for (int i = 5; i <= LIMIT; i+= 5) {
  14.             integers.add(i);
  15.         }
  16.         System.out.println(integers);
  17.     }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement