java编写跳动的爱心
时间: 2024-01-23 11:12:55 浏览: 30
以下是Java编写跳动的爱心的代码:
```java
public class Heart {
public static void main(String[] args) {
double x, y, size;
char[][] s = new char[30][80];
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
s[i][j] = ' ';
}
}
for (double i = 0; i < 2 * Math.PI; i += 0.01) {
for (double j = 0; j < 2 * Math.PI; j += 0.05) {
x = 16 * Math.pow(Math.sin(j), 3);
y = 13 * Math.cos(j) - 5 * Math.cos(2 * j) - 2 * Math.cos(3 * j) - Math.cos(4 * j);
size = Math.sin(i);
int x1 = (int) (x * size + 40);
int y1 = (int) (y * size + 15);
s[y1][x1] = '*';
}
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
System.out.print(s[i][j]);
}
System.out.println();
}
}
}
```
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)