代码

import static java.lang.Math.*;
public class Heart {
    public static void main(String[] args) {
            double x,y,a;
            char s[]=new char[]{'I',' ','l','o','v','e',' ','y','o','u','!'};
            int index=0;
            for(y=1.3f;y>-1.1f;y-=0.06f){
                index=0;
                for(x=-1.1f;x<=1.1f;x+=0.025f){
                    double result=x*x+pow((5.0*y/4.0-sqrt(abs(x))),2);
                    if(result<=1){
                        System.out.print((s[index]));
                        index=(index+1)%11;
                    }
                    else{
                        System.out.print(' ');
                    }
                }
                System.out.println(" ");
            }
    }
}

效果预览

效果预览

版权声明: 本博客所有文章除特别声明外,均采用署名-非商业性使用-相同方式共享 4.0 国际CC BY-NC-SA 4.0 )许可协议。转载请注明出处!
最后修改:2022 年 10 月 12 日 10 : 51 AM
如果觉得我的文章对你有用,请随意赞赏