-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaircase.java
More file actions
63 lines (53 loc) · 1.77 KB
/
Staircase.java
File metadata and controls
63 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Problem Statement: Staircase
Write a program to print a staircase of size n using the # symbol. The staircase will consist of n levels, and each level should be right-aligned.
The staircase is constructed such that each level contains a number of spaces followed by # symbols.
e.g., For an input of n = 6, the staircase has 6 levels. The first level has 5 spaces and 1 #, the second level has 4 spaces and 2 #, and so on,
until the last level, which has no spaces and 6 # symbols. Each level is printed on a new line
*/
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result
{
/*
* Complete the 'staircase' function below.
*
* The function accepts INTEGER n as parameter.
*/
public static void staircase(int n)
{
// Write your code here
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < n - i; j++)
{
System.out.print(" ");
}
for(int k = 0; k < i; k++)
{
System.out.print("#");
}
// Move to the next line after every #'s print
System.out.println();
}
}
}
public class Staircase
{
public static void main(String[] args) throws IOException
{
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine().trim());
Result.staircase(n);
bufferedReader.close();
}
}