java输出一颗爱心
时间: 2024-02-01 08:05:40 浏览: 21
以下是 Java 代码实现输出一颗爱心:
```
public class Heart {
public static void main(String[] args) {
double x, y, size;
char[][] pixels = new char[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
pixels[i][j] = ' ';
}
}
for (double t = 0; t < Math.PI; t += 0.01) {
x = 16 * Math.pow(Math.sin(t), 3);
y = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t);
x += 40;
y += 20;
size = Math.abs(Math.sin(t * 10));
if (size > 0.5) {
pixels[(int) y][(int) x] = '❤';
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
System.out.print(pixels[i][j]);
}
System.out.println();
}
}
}
```
输出结果如下:
```
❤ ❤
❤ ❤
❤ ❤
❤ ❤
❤ ❤
❤
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)