-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYourHeart.java
44 lines (31 loc) · 1.17 KB
/
YourHeart.java
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
44
// Heart Pattern
public class Pattern {
public static void main(String[] args) {
final int size = 4 ;
// upper part of Heart
for (int m = 0; m < size; m++) {
for (int k = 0; k <= 4 * size; k++) {
double pos1 = Math.sqrt(Math.pow(m - size, 2) + Math.pow(k - size, 2));
double pos2 = Math.sqrt(Math.pow(m - size, 2) + Math.pow(k - 3 * size, 2));
if (pos1 < size + 0.5 || pos2 < size + 0.5) {
System.out.print('*');
}
else {
System.out.print(' ');
}
}
System.out.print(System.lineSeparator());
}
// lower part of Heart
for (int m = 1; m <= 2 * size; m++) {
for (int k = 0; k < m; k++) {
System.out.print(' ');
}
for (int k = 0; k < 4 * size + 1 - 2 * m; k++) {
System.out.print("*");
}
System.out.print(System.lineSeparator());
}
System.out.println();
}
}