HackerRank : StairCase
Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example?
Input
You are given an integer depicting the height of the staircase.
You are given an integer depicting the height of the staircase.
Output
Print a staircase of height that consists of # symbols and spaces. For example for , here's a staircase of that height:
Print a staircase of height that consists of # symbols and spaces. For example for , here's a staircase of that height:
#
##
###
####
#####
######
Note: The last line has 0 spaces before it.
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i=0;i<n;i++){
for(int j=1;j<=n;j++){
System.out.print(j<n-i?" ":"#");
}
System.out.println();
}
}
}Sample Input:
6
Sample Output:
#
##
###
####
#####
######
Comments
Post a Comment