Staircase

Problem Statement
Your teacher has given you the task to draw the structure of a staircase. Being an expert programmer, you decided to make a program for the same. You are given the height of the staircase. You need to print a staircase as shown in the example.
Input Format
You are given an integer N depicting the height of the staircase.
Constraints
1N100
Output Format
Draw a staircase of height N in the format given below.
For example:
     #
    ##
   ###
  ####
 #####
######
Staircase of height 6, note that last line has 0 spaces before it.
Sample Input
6
Sample Output
     #
    ##
   ###
  ####
 #####
######



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

public class Solution {

    public static void main(String[] args) {
       Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if((i+j)>n)
{
System.out.print("#");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
    }
}

6 Comments

  1. That code don't work. i tried it.it print out this

    #




    #
    #



    #
    #
    #


    #
    #
    #
    #

    ReplyDelete
    Replies
    1. be careful between println() and print(). it will work.

      Delete
  2. yes, it doesnt work at all, no need to run, just simple handrun will explain why...

    ReplyDelete
Previous Post Next Post