-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiamondPattern.java
More file actions
41 lines (35 loc) · 1.14 KB
/
diamondPattern.java
File metadata and controls
41 lines (35 loc) · 1.14 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
public class diamondPattern {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = reader.read();
int space = n - 1;
for (int i = 0; i < n; i++) {
// loop for initially space,
// before star printing
for (int j = 0; j < space; j++)
System.out.print(" ");
// Print i+1 stars
for (int j = 0; j <= i; j++)
System.out.print("* ");
System.out.print("\n");
space--;
}
space = 1;
// run loop (parent loop)
// till number of rows
for (int i = n - 1; i > 0; i--) {
// loop for initially space,
// before star printing
for (int j = 0; j < space; j++)
System.out.print(" ");
// Print i stars
for (int j = 0; j < i; j++)
System.out.print("* ");
System.out.print("\n");
space++;
}
}
}