第八章練習題4

Duanhaifeng55發表於2018-04-09
public static void lingxing() {
Scanner input = new Scanner(System.in);
System.out.println("請輸入行數:");
int hang=input.nextInt();
int n=(hang+1)/2;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n-i; j++) {
System.out.print(" ");
}
for (int j2 = 1; j2 <= 2*i-1; j2++) {
System.out.print("*");
}
System.out.println("");
}
int m=hang-n;
for (int i = 0; i < m; i++) {
for (int j = 0; j < i+1; j++) {
System.out.print(" ");
}for (int j = 0; j < 2*m-i-i-1; j++) {
System.out.print("*");
}
System.out.println("");
}
}

相關文章