วันพุธที่ 18 กันยายน พ.ศ. 2556

=While=(H)

Programming Exercise
Proposition => In the exercise ,you use the nested loop to display a pattern of asterisk. (9 asterisk,8 asterisk,7 asterisk,6 asterisk,5 asterisk,4 asterisk,3 asterisk,2 asterisk,1 asterisk)

Translated into Thailand =>ให้ใช้ลูปซ้อนลูปในการแสดงวงกลม 9,8,7,6,5,4,3,2,1 วงกลม



Solution=> 
int x;
int y=10;
int r=10;
int n=9;
int count=9;
int c;
while(count<=n){  //ลูปแรกใช้ในการวนตามจำนวนแถวโดยจำนวนแถวขึ้นอยู่กับค่าn
  c=1;x=10;            
  while(c<=count){  //ลูปที่2ใช้ในการวนตามจำนวนoในแต่ล่ะแถว
    ellipse(x,y,r,r);  //คำสั่งใช้วาดวงกลม
    c++;
    x=x+r;  
  }
  y=y+r;
  count--;
}


Out put =>ooooooooo
                 oooooooo
                 ooooooo
                 oooooo
                 ooooo
                 oooo
                 ooo
                 oo
                 o

You can run code in http://processingjs.org/tools/processing-helper.html






text book name :Programming and problem solving with Java – 2nd edition
Author : Nell Dale and Chip Weems
              ISBN 978-0-7637-3402-2

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

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