Through the API document query math class method, print out approximate circle, as long as given the different radii, the size of the circle changes __java
Source: Internet
Author: User
[Java] View plain copy print? import java.lang.math; Public class mathdraw { /** * drawing function, input circle radius, Output circle */ public static void paint (int r) { //assume that the center of the circle is at coordinates (R,R) int x = 0; //x coordinates start int y = r * 2; //y coordinates start int c = 0 ; //Middle Space Quantity        INT Z&NBsp;= 2; //per line decrement, the step size is set to 2 to adjust the screen aspect ratio. for (int i  = R * 2; I >= 0; I = I-Z) { //gets the x value of the coordinates of the drawing * Point x = getx (r, y); //First draw the Y-value on the left * system.out.print (GetSpace (x) + "*"); c = (r-x) *2; //with center of output space //then draw the Y-value on the right *      &NBsp; system.out.println (Getspace (c) + "*"); //per Y-value decrement y-=z; } } /** * Get the picture * position, Input circle radius and coordinate y value, output coordinate x value */ Public static int getx (int r, int y) { //to take the long side of the triangle int h = y - r; Find the triangle short side length double l = Math.sqrt ((R * r) - (h * h)); //takes x values, Math.Round () returns the nearest integer return (int) math.round (r-l); } /** * Draw Space */ public static string getspace (int i) { String s = "";
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.