วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Loop (Easy)

 Write a Java program by using two for loops to produce the output shown below:



*******

******

*****

****

***

**

*
Solution:

void setup() {
  printStars();
}

void printStars() {
  int i = 0;
  while (i<=6) {
    int j = 1;
    while (j<=7-i) {
      print("*");
      j++;
    }
    println("");
    i++;
  }
}

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

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