Java简易版的爱心代码
时间: 2023-10-15 11:08:06 浏览: 128
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.01) {
x = 16 * Math.pow(Math.sin(i), 3);
y = 13 * Math.cos(j) - 5 * Math.cos(2 * j) - 2 * Math.cos(3 * j) - Math.cos(4 * j);
size = (x * x + y * y) / 200;
s[(int) (15 - y / size)][(int) (40 + x / size)] = '*';
}
}
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 80; j++) {
System.out.print(s[i][j]);
}
System.out.println();
}
}
}
```
阅读全文