用Java写一个love爱心
时间: 2023-12-09 16:05:19 浏览: 34
以下是用 Java 编写的爱心图案代码:
```
public class LoveHeart {
public static void main(String[] args) {
int size = 10;
for (int y = size; y >= -size; y--) {
for (int x = -size; x <= size; x++) {
double d = Math.pow(Math.pow(x, 2) + Math.pow(y, 2) - Math.pow(size, 2), 3) - Math.pow(x, 2) * Math.pow(y, 3);
if (d <= 0) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
```
输出结果如下:
```
* *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* *
```
这个爱心图案的绘制也是基于坐标系的,不过采用了不同的点的计算方式,通过对点的计算来实现爱心的绘制。