วันเสาร์ที่ 20 กรกฎาคม พ.ศ. 2556

Loop (Easy)

Proposition
Write a code segment that sums the even integers from 16 through 26, inclusive.

Code

int sum=0;
int start=16;
int finish=26;
int i;
for (i=start;i<finish;i++) {
  if (i%2==0) sum+=i;
}
println(sum);


Output
126

Text book name : Programming and Problem solving with Java second edition
Author : Nell Dale and Chip Weems
ISBN : 978-0-7637-3402-2


ไม่มีความคิดเห็น:

แสดงความคิดเห็น