Created
September 20, 2017 10:14
-
-
Save javamultiplex/9325e512ce0799ec4f6ac4d44ae16d2b to your computer and use it in GitHub Desktop.
Project Euler Problem 1: Multiple of 3 or 5 below 1000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javamultiplex.projecteuler; | |
/** | |
* | |
* @author Rohit Agarwal | |
* @category Project Euler Problem 1 | |
* @problem Multiples of 3 and 5 | |
* | |
*/ | |
public class Problem1 { | |
public static void main(String[] args) { | |
int sum = 0; | |
for (int num = 1; num < 1000; num++) { | |
/* | |
* On dividing a number by 3 or 5, if we are getting remainder zero | |
* it means that number is multiple of either 3 or 5 | |
*/ | |
if (num % 3 == 0 || num % 5 == 0) { | |
sum = sum + num; | |
} | |
} | |
System.out.println("\nThe sum of all multiples of 3 or 5 below 1000 is : "+ sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment