Import Java.lang.Math; public class Mathdraw {/** * paint function, input circle radius, Output circle */public static void paint (int r) {//Assume that the center point is at coordinates (r,r) int x = 0;//x coordinates begin with int y = R * 2; The coordinates of y begin with int c = 0; The number of intermediate spaces int z = 2; Each line is decremented, and the step size is set to 2 to adjust the screen aspect ratio. for (int i = R * 2; I >= 0; i = i-z) {//Get picture * Point coordinates x value x = GetX (r, y); First draw the Y value on the left of the * System.out.print (Getspace (x) + "*"); c = (r-x) * *; With the center corresponding to the output space//and then draw the Y value on the right of the * SYSTEM.OUT.PRINTLN (Getspace (c) + "*"); Each time the Y value decrements y-=z; }}/** * Get the picture position, enter the circle radius and coordinate y value, output coordinate x value */public static int GetX (int r, in T y) {//Take right triangle long side length int h = y-r; Right triangle short side long double L = math.sqrt (R * r)-(H * h)); Takes an 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; } public static void Main (string[] args) {//Call paint function, parameter is circle radius paint (6); } }
[Transfer from 8679856#]
[Go] Print an approximate circle, given a different radius, the size of the circle changes