Project Euler #1 in Java

前端 未结 8 1618
旧时难觅i
旧时难觅i 2021-02-04 18:22

I\'m having problems with this code. I don\'t want to look at others, so I\'m wondering what\'s wrong with mine.

If we list all the natural numbers below 10 that are mu

8条回答
  •  梦谈多话
    2021-02-04 18:35

    just write this simple java code.

     public static void main(String[] args)
    {
    int i,sum=0;
    for ( i = 3; i <1000; i++)
     {
     if ((i % 3 == 0)||(i%5==0) )
     sum=sum+i;
     }
    System.out.print(sum);
    }
    

    You will get the output as 233168

提交回复
热议问题