代码语言:javascript复制
package *;
/**
* @program: data-structure
* @description: 圆形
* @author: ChenWenLong
* @create: 2019-09-10 16:08
**/
public class Circle {
public static void main(String[] args) {
circle(60);
}
/**
* 功能描述:
* 〈指定半径打印圆〉
*
* @params : [r]
* @return : void
* @author : cwl
* @date : 2019/9/10 16:11
*/
public static void circle(int r){
//y的步长为2,改变y的步长可以将圆形变成椭圆
for (int y = 0; y <= 2 * r; y = 2) {
int x = (int)Math.round(r - Math.sqrt(2 * r * y - y * y));
int len = 2 * (r - x);
for (int i = 0; i <= x; i ) {
System.out.print(' ');
}
System.out.print('*');
for (int j = 0; j <= len; j ) {
System.out.print(' ');
}
System.out.println('*');
}
}
}