Java to realize heart-shaped pattern | Peach Heart

Source: Internet
Author: User
Tags abs

There is something wrong if you are thedouble type minus an int type. Because when you are refer to a double type.

Eg. Double 1.0;

Some IDE may get the value 1.00000000000

and others may get 0.999999999999999

But They represent the same number.

The same problem here.

So your must find the precise position.

 

For that we use the function (x^2+y^2-1) ^3-x^2*y^3 = 0;

single Peach Heart:

       public static void Main (String argv[]) {for
              (float y = (float) 1.5;y>-1.5;y-=0.1)
              {for
                     (float x= (float)-1 .5;x<1.5;x+= 0.05)
                     {
                           float a = x*x+y*y-1;
                           if ((a*a*a-x*x*y*y*y) <=0.0)
                           {
                                  
                                  
                                  System.out.print ("*");
                           
                           }
                           else
                                  System.out.print ("");
                     }
                     System.out.print ("\ n");
              }
       

For two of the pic

       public static void Main (String argv[]) {for (Float y = (float) 1.5;y>-1.5;y-=0.1) {
                     for (float x= (float) -1.5;x<1.5;x+= 0.05) {float A = x*x+y*y-1;  if ((a*a*a-x*x*y*y*y) <=0.0) {if (Math.Abs (x+0.100000712) <=1e-6 && Math.Abs (y-0.6999998) <=1e-6) {SYSTEM.OUT.P
                                   Rint ("F");
                            Continue
                            if (Math.Abs (x+0.050000306) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("R");
                            Continue
                            if (Math.Abs (x+-3.0621885e-7) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                   {                System.out.print ("a");
                            Continue
                            if (Math.Abs (x-0.049999695) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("n");
                            Continue
                            if (Math.Abs (x-0.100000001) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("K");
                            Continue
                     
                     } System.out.print ("*");
               else System.out.print ("");  for (float x= (float) 1.5;x<4.5;x+= 0.05) {float A = (x-3) * (x-3) +y*y-1;
                     Boolean flag = false; if ((a*a*a-(x-3) * (x-3) *y*y*y) <=0.0) {if (Math.Abs (x-3+0.100000712) <=1 E-6 && Math.Abs (y-0.6999998) <=1e-6) {System.ou
                                     T.print ("C");
                                   Flag = true;
                            Continue
                            } if ((Math.Abs (x-2.9499986)) <= 1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("a");
                            Continue
                            if (Math.Abs (x-2.9999986) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("s");
                            Continueif (Math.Abs (x-3.0499985) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("I");
                            Continue
                            if (Math.Abs (x-3.0999985) <=1e-6 && math.abs (y-0.6999998) <=1e-6)
                                   {System.out.print ("O");
                            Continue
                     
                     } System.out.print ("*");
               else System.out.print ("");
        } System.out.print ("\ n");
 }
       }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.