[Go] Print an approximate circle, given a different radius, the size of the circle changes

Source: Internet
Author: User

    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

Related Article

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.