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++;
}
}
printStars();
}
void printStars() {
int i = 0;
while (i<=6) {
int j = 1;
while (j<=7-i) {
print("*");
j++;
}
println("");
i++;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น