Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. package ovh.unlimitedbytes.project;
  2.  
  3. public class Project {
  4.  
  5. /**
  6. * If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
  7. * The sum of these multiples is 23.
  8. * Find the sum of all the multiples of 3 or 5 below 1000.
  9. *
  10. * @param args
  11. */
  12. public static void main(String[] args) {
  13.  
  14. int sum = 0;
  15.  
  16. for ( int i = 1; i < 1000; i++ ) {
  17. if( i % 3 == 0 || i % 5 == 0 ) {
  18. sum += i;
  19. }
  20. }
  21.  
  22. System.out.println("Sum: " + sum);
  23.  
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement