本帖最後由 葉桔良 於 2022-3-25 19:58 編輯
請以for迴圈列出以下圖形
- public class Test
- {
- public static void main(String args[])
- {
- int s, star=13;
- System.out.println("How many star do you want?");
- for (int i=0; i<star ; i++ ) //i=8
- {
- s = star / 2 - i; //s=-2
- if (s < 0)
- s = -s;
- for (int j = 0 ; j < s ; j++ ) //j=0~2
- System.out.print(" ");
- for (int k = 0 ; k < star - 2 * s ; k++ ) //k=9
- System.out.print("*");
- System.out.println();
- }
- }
- }
複製代碼 |