DEV Community

k@k
k@k

Posted on

Staircase Problem

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.

Function Description

Complete the staircase function in the editor below. It should print a staircase as described above.

staircase has the following parameter(s):

n: an integer

Input Format

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

Constraints

0<n<=100

Output Format

Print a staircase of size n using # symbols and spaces.

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

My Solution

import java.io.;
import java.math.
;
import java.security.;
import java.text.
;
import java.util.;
import java.util.concurrent.
;
import java.util.regex.*;

public class Solution {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1;i<=n;i++){
for(int k=n;k>i;k--){
System.out.printf(" ");
}
for(int j=1;j<=i;j++){
System.out.printf("#");
}
System.out.println();
}
}
}

Please comment your approach

Top comments (0)