请用java打印出一个填充过的心形图案
时间: 2024-03-13 12:45:29 浏览: 82
以下是Java代码,可以打印出一个填充过的心形图案:
```java
public class Heart {
public static void main(String[] args) {
int size = 10;
for (int i = size / 2; i <= size; i += 2) {
for (int j = 1; j < size - i; j += 2) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
for (int j = 1; j <= size - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = size; i >= 1; i--) {
for (int j = i; j < size; j++) {
System.out.print(" ");
}
for (int j = 1; j <= (i * 2) - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
```
输出结果:
```
**** ****
****** ******
****************
******************
********************
********************
******************
****************
**************
************
**********
********
******
****
**
```
阅读全文