Advertisement
JeffGrigg

ThreesAndFives

Oct 9th, 2020
2,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.52 KB | None | 0 0
  1. public class ThreesAndFives {
  2.  
  3.     private static final int LIMIT = 10_000_000;   // = 10^7
  4.  
  5.     public static void main(String[] args) {
  6.         int threes = 3;
  7.         int fives = 5;
  8.         while (threes <= LIMIT || fives < LIMIT) {
  9.             final int smaller = Math.min(threes, fives);
  10.             System.out.println(smaller);
  11.             if (threes == smaller) {
  12.                 threes += 3;
  13.             }
  14.             if (fives == smaller) {
  15.                 fives += 5;
  16.             }
  17.         }
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement