  
|
計算333~999間所有3的倍數總和
試利用 for 迴圈,計算333~999間所有3的倍數總和。
333+336+339+...+996+999= ?
 - public class Ch12 {
- public static void main(String[] args) {
-
- int sum=0;
-
- for(int i=333; i<=999; i+=3)
- sum+=i; //sum=sum+i
-
- System.out.println("333~999間所有3的倍數總和為: "+sum);
- }
- }
複製代碼 |
|