Skip to content

Commit 7787b12

Browse files
committed
added 6kyu problem
1 parent b9b375d commit 7787b12

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎CodeWars/6kyu/Diamond.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.*;
2+
3+
class Diamond {
4+
public static String print(int n) {
5+
6+
if (n < 0 || n % 2 == 0)
7+
return null;
8+
9+
StringBuilder str = new StringBuilder();
10+
11+
for (int i = 1; i <= n; i += 2) {
12+
str.append(" ".repeat((n - i) / 2)).append("*".repeat(i)).append("\n");
13+
}
14+
15+
for (int i = n - 2; i > 0; i -= 2) {
16+
str.append(" ".repeat((n - i) / 2)).append("*".repeat(i)).append("\n");
17+
}
18+
19+
return str.toString();
20+
}
21+
}

0 commit comments

Comments
 (0)