给我java跳动爱心代码,百分百还原跳动的爱心!
时间: 2023-12-14 15:34:50 浏览: 77
以下是Java实现跳动的爱心代码的例子:
```java
public class Heart {
public static void main(String[] args) {
double x, y, size;
char[][] s = new char[30][80];
while (true) {
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
s[i][j] = ' ';
}
}
for (int i = 0; i < 360; i++) {
size = Math.sin(Math.toRadians(i));
x = size * Math.cos(Math.toRadians(i)) * 15 + 40;
y = -size * Math.sin(Math.toRadians(i)) * 15 + 15;
s[(int) y][(int) x] = '*';
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
System.out.print(s[i][j]);
}
System.out.println();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
阅读全文