java爱心动态代码
时间: 2023-11-20 12:58:53 浏览: 107
以下是Java实现爱心动态代码的例子:
```java
public class Heart {
public static void main(String[] args) {
double x, y, size;
char[][] heart = new char[30][60];
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 60; j++) {
heart[i][j] = ' ';
}
}
for (double i = 0; i < 2 * Math.PI; i += 0.01) {
for (double j = 0; j < 2 * Math.PI; j += 0.01) {
x = 16 * Math.pow(Math.sin(i), 3);
y = 13 * Math.cos(i) - 5 * Math.cos(2 * i) - 2 * Math.cos(3 * i) - Math.cos(4 * i);
size = Math.sin(j);
int x1 = (int) (x * size + 30);
int y1 = (int) (y * size + 15);
heart[y1][x1] = '*';
}
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 60; j++) {
System.out.print(heart[i][j]);
}
System.out.println();
}
}
}
```
阅读全文