Scanner x = new Scanner(System.in);
byte num, r, c;
System.out.print("Enter a number: ");
num = x.nextByte();
for (r = 1; r <= num; r++) {
for (c = 1; c <= r; c++) {
System.out.print("*");
}
System.out.println();
}
示例输出:
Enter a number: 4
*
**
***
****
如何更改输出:
*
**
***
****
至
****
***
**
*