Project Euler 1

Project Euler

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.

  • multiples→倍数
  • below 10→10未満


10未満の自然数ならば、3か5の倍数は3,5,6,9である。それらの倍数の和は23になる。
1000未満で全ての3か5の倍数の和を探せ

public class Euler1 {
	
	public static void main(String[] args)
	{
		int a = 0;
		//1000未満
		for(int i=1;i<1000;i++)
		{
			//3と5の公倍数
			if(i%3 == 0 && i%5 == 0){
				a+=i;
			}
			//3の倍数
			else if(i%3 == 0)
			{
				a+=i;
			}
			//5の倍数
			else if(i%5 == 0)
			{
				a+=i;
			}
		}
		System.out.print(a);
	}
}

Congratulations, the answer you gave to problem 1 is correct.