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 integerN depicting the height of the staircase.
You are given an integer
Output
Print a staircase of heightN that consists of # symbols and spaces. For example for N=6 , here's a staircase of that height:
Print a staircase of height
#
##
###
####
#####
######
Note: The last line has 0 spaces before it.
Solution:
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 in = new Scanner(System.in);
int n = in.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=n;j>i;j--)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("#");
}
System.out.println();
}
}
}
nice post
ReplyDeletekajal hot