Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created February 7, 2015 22:17
Show Gist options
  • Save dmnugent80/9402eb9a751b04af3315 to your computer and use it in GitHub Desktop.
Save dmnugent80/9402eb9a751b04af3315 to your computer and use it in GitHub Desktop.
Sum Multiples of Thee and Five
public class Main
{
public static void main(String[] args)
{
MultiplesThreeAndFive myObject = new MultiplesThreeAndFive();
int sum = myObject.getSum(1000);
System.out.print("sum: " + sum);
}
}
// this will become its own file too (and these can be in any order)
public class MultiplesThreeAndFive
{
public int getSum(int max){
int sum = -99;
for (int i = 1; i < max; i++){
if (i % 3 == 0 || i % 5 == 0){
if (sum == -99)
sum = i;
else
sum += i;
}
}
return sum;
}
}
/*Output
sum: 233168
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment