Multiples of 3 and 5

Multiples of 3 and 5

Answer is 233168 pragmatically.

I did not use the Math to get the answer.

public class Main {
public static int multiple3and5below1000() { 
int sum = 0; 
for (int i = 3; i < 1000; i++) { 
if ((i >= 3 && ((i % 3) == 0) || (i >= 5 && ((i % 5) == 0)))) 
sum += i; } 
return sum; }
 public static void main(String[] args) { 
 System.out.println(multiple3and5below1000()); }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s