用Java打印爱心

代码如下:

package practice;

//打印爱心
public class Heart {
    public static void main(String[] args) throws Exception{
        for (double i = 1.5; i > -1.5; i-=0.1) {
            for (double j = -2; j<2;j+=0.05 ){
                double a = i*i+j*j-1;
                if ((a*a*a-i*i*i*j*j) <=0.0){
                    Thread.sleep(10);
                    System.out.print("*");
                } else System.out.print(" ");
            }
            System.out.println();
        }
    }
}

用Java打印爱心_第1张图片

 

你可能感兴趣的:(java)