For example: through the API document query math class method, print the following approximate circle, as long as given a different radius, the size of the circle changes.
Import Java.lang.Math; public class Mathdraw {/** * drawing function, input circle radius, Output circle */public static void paint (int R) {//Assuming the center of the circle at coordinates (r,r) int x = 0;//x coordinates start int y = R * 2; The coordinates of y begin int c = 0; Middle space quantity int z = 2;
Decrements per line, and the step size is set to 2 to adjust the aspect ratio of the screen.
for (int i = R * 2; I >= 0; i = i-z) {//get x Value x = GetX (r, y) of the coordinates of the drawing * point;
First draw the Y-value on the left side of the * System.out.print (Getspace (x) + "*"); c = (r-x) *2;
With the center of the output space//and then draw the Y-value on the right side of the * SYSTEM.OUT.PRINTLN (Getspace (c) + "*");
Decreasing the Y value each time y-=z; }/** * Get picture * position, Input circle radius and coordinate y value, output coordinate x value/public static int GetX (int
R, int y) {//Take the long side of the right-angled triangle int h = y-r; Find the triangle short side long double L = math.sqrt (R * r)-(H * h));
Taking the X value, Math.Round () returns the nearest integer return (int) math.round (r-l); /** * Draw space */public static string getspace (int i) {string
s = "";
for (int j = 0; J < i; J +) {s + = "";
return s;
The public static void main (string[] args) {//calls the drawing function, and the parameter is the radius of the circle paint (6); }
}
To run the program:
Another one:
public class Circledraw { /** * @param args * @author Bigboy & nbsp; * public static void Main (string[] args) { // TODO auto-generated Method stub //definition radius int R
= 6; //defines y as the ordinate of a circle, where y=y+2 is the step to set the ordinate, you can adjust the ellipse's "fat thin" for (int y = 0; y <= 2 * r; y = y + 2) { long x = MATH.R
Ound (R-MATH.SQRT (2 * R * y-y * y)); for (int i = 0; I <= 2 * r; i++) { &NBSP;&NBSP;&N Bsp //i==x refers to a vertical axis corresponding to a ordinate, i==2*r-x refers to the ordinate corresponding to the second horizontal axis if (i = = X | | | = = 2 * r-x) { system.out.print ("*");  } else { &
nbsp; system.out.print ("");  } &
nbsp; } system.out.print ("\ n");
}  }
To run the program: