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
1≤N≤100
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();
}
}
}
That code don't work. i tried it.it print out this
ReplyDelete#
#
#
#
#
#
#
#
#
#
be careful between println() and print(). it will work.
Deleteyes, it doesnt work at all, no need to run, just simple handrun will explain why...
ReplyDeletecopy paste and run , it will work :P
DeleteThis works perfectly..
ReplyDeletethanks :)
Delete