← all problems

printPyramid 🌶️🌶️

Write a method that takes one int parameter, n, and prints a centered pyramid of asterisks with n rows. Row i (counting from 1) has (n - i) period characters (.) followed by (2i - 1) asterisks — periods stand in for the leading spaces a real pyramid would use, since leading spaces cannot be checked reliably here.

For example, printPyramid(4) prints:

...*..***.************