效果图

简单的循环语句写的爱心代码,需要自取:
public class Love {
public static void main(String[] args) throws InterruptedException {
int count=0;
for (float y=2.5f;y>-2.0f;y-=0.12f){
for (float x=-2.3f;x<2.3f;x+=0.041f){
float a = x*x+y*y-4f;
if ((a*a*a-x*x*y*y*y)<-0.0f){
String str="♥";
int num =count%str.length();
System.err.print(str.charAt(num));
count++;
}else{
System.err.print(" ");
}
}
System.err.println();
Thread.sleep(100);
}
}
}
“♥”字符是可以改变的。
这篇博客分享了一段使用简单循环语句编写的Java代码,该代码能在控制台绘制出爱心图案。作者指出,代码中的'♥'字符可以替换,且提供了代码运行时每行之间暂停的实现方式,为读者展示了一种创意编程技巧。
2694

被折叠的 条评论
为什么被折叠?



