//試利用while迴圈計算2 + 4 + 6 +L+ n的總和,其中n為200。
public class P5_3_21 {
public static void main(String[] args) {
int n=2;
int sum=0;
while(n<=200){
if(n%2==0){
sum+=n;
}
}System.out.println("總和=="+sum);
n++;
}

}

/*

1~20 中的偶數==
2 4 6 8 10 12 14 16 18 20 偶數的平方值之和==1540

*/

arrow
arrow
    文章標籤
    java
    全站熱搜

    goodlucky23 發表在 痞客邦 留言(0) 人氣()