forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathEkansh
44 lines (40 loc) · 1.62 KB
/
Ekansh
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
class Pattern {
public static void main(String[] args) {
final String message = "Please be the Semicolon to my life";
final int n = 10;
System.out.println("\n\n\nRoses are red,\nViolets are blue\nPlease be my valentine\nor I'll debug you");
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 4 * n; j++) {
double d1 = Math.sqrt(Math.pow(i - n, 2) + Math.pow(j - n, 2));
double d2 = Math.sqrt(Math.pow(i - n, 2) + Math.pow(j - 3 * n, 2));
if (d1 < n + 0.5 || d2 < n + 0.5) {
System.out.print('*');
} else {
System.out.print(' ');
}
}
System.out.print(System.lineSeparator());
}
for (int i = 1; i < 2 * n; i++) {
for (int j = 0; j < i; j++) {
System.out.print(' ');
} for (int j = 0; j < 4 * n + 1 - 2 * i; j++) {
if (i >= 2 && i <= 4) {
int idx = j - (4 * n - 2 * i - message.length()) / 2;
if (idx < message.length() && idx >= 0) {
if (i == 3) {
System.out.print(message.charAt(idx));
} else {
System.out.print(' ');
}
} else {
System.out.print('*');
}
} else {
System.out.print('*');
}
}
System.out.print(System.lineSeparator());
}
}
}