-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimond.java
More file actions
29 lines (27 loc) · 787 Bytes
/
dimond.java
File metadata and controls
29 lines (27 loc) · 787 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
26
27
28
29
class Main {
public static void dimond(int n) {
// Top Half
for (int i = 0; i <= n; i++) {
for (int j = n; j >= i; j--) {
System.out.print(" ");
}
for (int j = 1; j <= (2 * i + 1); j++) {
System.out.print("*");
}
System.out.println();
}
// Bottom Half (Fixed)
for (int i = n - 1; i >= 0; i--) { // Fix: Loop properly downward
for (int j = n; j >= i; j--) {
System.out.print(" ");
}
for (int j = 1; j <= (2 * i + 1); j++) {
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
dimond(5);
}
}