java爱心表白代码
时间: 2023-11-30 16:42:46 浏览: 167
以下是Java实现爱心表白的代码:
```java
public class Love {
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.05) {
for (double j = 0; j < 2 * Math.PI; j += 0.1) {
x = 2 * Math.sin(i) * (Math.pow(Math.sin(j), 2)) + 0.5;
y = Math.cos(j) * Math.sin(i) + 0.5;
size = (x * x + y * y) * 0.1;
s[(int) (y * 30)][(int) (x * 40 + 20)] = size > 1 ? ' ' : "LOVE".charAt((int) (size * 4));
}
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
System.out.print(s[i][j]);
}
System.out.println();
}
}
}
```
阅读全文