Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. /*        If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
  4.           The sum of these multiples is 23.
  5.           Find the sum of all the multiples of 3 or 5 below 1000.
  6.  
  7.           21 = 3 + 5 + 6 + 10
  8. */
  9. class Ex1 {
  10.     static void run(int x){
  11.         int i = 0,tmp = 0,results = 0;
  12.         while(true){
  13.             i++;
  14.             tmp = i*3;
  15.             if(tmp>x)break;
  16.             results+=tmp;
  17.             tmp = i*5;
  18.             if(tmp>x)continue;
  19.             results += tmp;
  20.         }
  21.         System.out.println(results);
  22.  
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement