java输出一个爱心
时间: 2024-02-20 08:00:37 浏览: 35
以下是Java代码,可以输出一个爱心图案:
```java
public class HeartShape {
public static void main(String[] args) {
int x, y;
double f;
for (y = -15; y <= 15; y++) {
for (x = -30; x <= 30; x++) {
f = Math.pow(Math.pow(x * 0.05, 2) + Math.pow(y * 0.1, 2) - 1, 3) - Math.pow(x * 0.05, 2) * Math.pow(y * 0.1, 3);
System.out.print(f <= 0.0 ? "*" : " ");
}
System.out.println();
}
}
}
```
输出结果如下:
```
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)