Problem:
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.
Answer:
public static double count(int max,int count){
int a = 0;
double sum =0;
for(int i=2;i<max;i++){
if(count*i >= max) break;
a = i;
}
out(a);
for(int i=1;i<=a;i++){
sum+=i;
}
out(sum);
return sum*count;
}
public static void main(String[] args){
out(count(1000,3)+count(1000,5)-count(1000,15));
}