写一段java爱心代码
时间: 2023-04-08 19:05:14 浏览: 152
java编写的爱心代码.java
当然可以,以下是一段简单的 Java 爱心代码:
```
public class Love {
public static void main(String[] args) {
for (int i = -3; i <= 3; i++) {
for (int j = -3; j <= 3; j++) {
if (i * i + j * j <= 9) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
if (i * i + j * j <= 4) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println(" * * * ");
System.out.println(" * * ");
System.out.println(" * ");
}
}
```
这段代码可以输出一个简单的爱心图案,希望你喜欢!
阅读全文