Java Approximate circle

Source: Internet
Author: User

and schematic diagram

Code:

1  Public classCircle2 {3      Public Static voidMain (string[] args)4     {5         intRADIUS = 10;6System.out.println ("Approximate circle with output radius + radius +");7 Paint (RADIUS);8     }9 Ten      Public Static voidPaintintR) One     { A         //assuming the center of the Circle is (R, R) -         intX//current x-coordinate -         inty = 2 * r;//current y-coordinate the         intSpace//number of spaces in the middle of each line -         intD = 2;//Descending amount per line -          for(intj = 2*r; j>=0; j=j-d) -         { +x =GetX (R, y); -Space = 2 * (rx); +System.out.print (Getspace (x+10) + "*");//the * number on the left with 10 units shifted to the right ASystem.out.println (Getspace (space) + "*");//the * number on the right atY-=D; -         } -     } -  -      Public Static intGetX (intRinty) -     {    { in  -         Doubletempx; toTEMPX = Math.sqrt (R*r-(y-r) * (yR)); +         return(int) Math.Round (-tempx +r);//Math.Round (double D) returns the nearest parameter to a long, so a type cast is required -     } the  *      Public StaticString Getspace (intspace) $     {Panax NotoginsengString s = ""; -          for(inti=0; i<space; i++) the         { +s = s+ ""; A         } the         returns; +     } -}
View Code

Java Approximate circle

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.