-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamond_Fixed.java
More file actions
25 lines (24 loc) · 908 Bytes
/
Diamond_Fixed.java
File metadata and controls
25 lines (24 loc) · 908 Bytes
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
public class Diamond_Fixed {
public static void main(String[] args) {
int len = 5;
int right = len;
int left = len;
for (int i = 1; i <= len + 1; right++, left--, i++) {
for (int j = 1; j <= (2 * len - 1); j++) {
if (left == 0) {
left += 2;
right -= 2;
for (; left <= right; left++, right--) {
for (int k = 1; k <= (2 * len - 1); k++) {
if ((k >= left) && (k <= right)) System.out.print("*");
else System.out.print(" ");
}
System.out.println();
}
} else if ((j >= left) && (j <= right)) System.out.print("*");
else System.out.print(" ");
}
System.out.println();
}
}
}