-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDiamondPattern.java
More file actions
43 lines (41 loc) · 1.06 KB
/
DiamondPattern.java
File metadata and controls
43 lines (41 loc) · 1.06 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
package pattern2;
import java.util.Scanner;
public class DiamondPattern {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
// first half of the pattern
int n1 = N / 2 + 1;
int i = 1;
while (i <= n1) {
int spaces = 1;
while (spaces <= (n1 - i)) {
System.out.print("\t");
spaces++;
}
int j = 1;
while (j <= (2 * i - 1)) {
System.out.print("*\t");
j++;
}
i++;
System.out.println();
}
// second half of the pattern
i = N - n1;
while (i >= 1) {
int spaces = 1;
while (spaces <= (n1 - i)) {
System.out.print("\t");
spaces++;
}
int j = 1;
while (j <= 2 * i - 1) {
System.out.print("*\t");
j++;
}
System.out.println();
i--;
}
}
}