MultiplesOf3And5.java 561 B

12345678910111213141516171819202122
  1. public class MultiplesOf3And5 {
  2. // Find the sum of all the multiples of 3 or 5 below 1000.
  3. public static int getSumOf3And5Multiples() {
  4. int total = 0;
  5. for (int i = 1; i < 1000; i++) {
  6. if (i % 3 == 0 || i % 5 == 0)
  7. total += i;
  8. else
  9. continue;
  10. }
  11. return total;
  12. }
  13. public static void main(String[] args) {
  14. int multiplesSum = getSumOf3And5Multiples();
  15. System.out.print("Here is the sum of all the multiples of 3 or 5 ");
  16. System.out.println("that are between 1 and 1000: " + multiplesSum + ".");
  17. }
  18. }