java李峋爱心代码
时间: 2023-11-19 13:56:35 浏览: 161
Java李峋爱心代码是一段Java代码,它的输出结果是一个爱心图案。这段代码是由中国程序员李峋编写的,他在2011年情人节当天将这段代码分享在了他的博客上,从而走红网络。以下是Java李峋爱心代码的实现:
```java
public class Love {
public static void main(String[] args) {
double x, y, size = 100;
char[][] s = new char[176][176];
while (true) {
for (int i = 0; i < 176; i++) {
for (int j = 0; j < 176; j++) {
s[i][j] = ' ';
}
}
for (int i = 0; i < 360; i++) {
double t = i * Math.PI / 180;
x = Math.sin(t);
y = Math.cos(t);
double q = x * x + 2 * y * y;
if (q > 1 - 1 / size && q < 1 + 1 / size) {
int a = (int) (x * size + size / 2);
int b = (int) (y * size + size / 2);
s[b][a] = '*';
}
}
for (int i = 0; i < 176; i++) {
for (int j = 0; j < 176; j++) {
System.out.print(s[i][j]);
}
System.out.print("\n");
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
阅读全文