/*
* 試利用while 迴圈與if 敘述,判斷並列印出1~20 中所有的偶數,同時計算這些偶數的
平方值之和。
*/
public class P5_3_20 {
public static void main(String[] args) {

int count=1;
int x=0;
int y=0;
int sum=0;
System.out.println("1~20 中的偶數==");
while(count<=20){
if(count%2==0){
System.out.print(count+" ");
x=count;
y=x*x;
sum+=y;
}
count++;
} System.out.print("偶數的平方值之和=="+sum+"\t");
System.out.println();

}
}

/*

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

*/

arrow
arrow
    文章標籤
    java
    全站熱搜

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