problem-
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/*
*
* Ratnadeep Sen
* National Institute Of Technology Silchar -India (NITS)
*
*/
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 2;i<=n+1;i++)
{
int k = 0;
for(int j = 1;j<=(n-i)+1;j++)
{
System.out.print(" ");
}
while(k!=(((2*i)-1)/2))
{
System.out.print("#");
k++;
}
System.out.print("\n");
}
}
}
Consider a staircase of size :
#
##
###
####
Observe that its base and height are both equal to , 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 .
Input Format
A single integer, , denoting the size of the staircase.
Output Format
Print a staircase of size using
#
symbols and spaces.
Note: The last line must have spaces in it.
Sample Input
6
Sample Output
#
##
###
####
#####
######
Explanation
The staircase is right-aligned, composed of
#
symbols and spaces, and has a height and width of .
solution-
import java.io.*;import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/*
*
* Ratnadeep Sen
* National Institute Of Technology Silchar -India (NITS)
*
*/
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 2;i<=n+1;i++)
{
int k = 0;
for(int j = 1;j<=(n-i)+1;j++)
{
System.out.print(" ");
}
while(k!=(((2*i)-1)/2))
{
System.out.print("#");
k++;
}
System.out.print("\n");
}
}
}
No comments:
Post a Comment