HackerRank – Staircase (Java)

HackerRank – Staircase (Java)



Consider a staircase of size n = 4:

Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

Input Format

A single integer, , denoting the size of the staircase.

Output Format

Print a staircase of size using # symbols and spaces.

Note: The last line must have 0 spaces in it.

Sample Input

Sample Output


The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n = 6.


The staircase is actually printed on a 2D array.

If (row index + column index) > n, print “#”; otherwise, print ” “.

Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *