java輸入金字塔行數?
代碼如下:
import java.util.Scanner;public class App13 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in)
;System.out.print("請輸入金字塔層數:")
;int n = scanner.nextInt()
;for (int i = n; i >= 0; i--) {for (int k = 0; k < n - i; k++)System.out.print(' ')
;for(int j = 0; j < 2 * i - 1; j++)System.out.print('*')
;System.out.println();}}
}運行結果: