public class Problem_1_Multiples_Of_3_And_5 { /* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. */ public static void main (String[] args) { int sum = 0; boolean threeMultiple = false, fiveMultiple = false; for (int i = 3; i < 1000; i++) { threeMultiple = i % 3 == 0; fiveMultiple = i % 5 == 0; if (threeMultiple || fiveMultiple) sum += i; } System.out.println(sum); } }DOWNLOAD
Created: February 10, 2014
Completed in full by: Michael Yaworski