Kotlinlearncs.online LogoJava
Return to List

Solve: Print Pyramid Function

Created By: Justin Maier
/ Version: 2025.9.0

Write a function printPyramid that takes a single int argument and prints a pyramid-shaped star pattern with as many rows as the argument.

For example, when the argument is 3 you should print the pattern:

  *
 ***
*****

When the argument is 4, you should print:

   *
  ***
 *****
*******

If the argument is 0 or less, print nothing.

Remember, you can use System.out.print to print without creating a new line.

Related Lessons

Stuck? You may find these lessons helpful: