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

Loop (Medium)

Proposition
Write a nested loop code segment that produces this output:
1
12
123
1234


Code
void setup() {
  int c = 1;
  int n = 5;
  while (c <= n) {

    Row(c);
    println();
    c = c + 1;
  }


void Row(int c) {
  int a = 1;
  while (a < c) {
    String sa = str(a);
    print(sa);
    a = a + 1;
  }

}


Output
1
12
123
1234

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


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

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