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