A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© faith 中级黑马   /  2014-4-15 10:29  /  1996 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

如何只输入半径在 就能用*画个圆出来?

3 个回复

倒序浏览

        import java.util.*;

        public class MathRound

        {

          private static int radius;

          public static void main(String[] args)

          {

                int dist;

                System.out.println("Input the radius(R > 2):");

                Scanner scan = new Scanner(System.in);

                try{

                  radius = Integer.parseInt(scan.next());

                }catch(Exception e)

                {

                  e.printStackTrace();

                }

                radius = 2*radius;

                System.out.println("===========When R < 20 works well==============");

                for(int i = 0; i <= radius; i ++)

                {

                  int j = 0 ;

                  if(i == radius/2)//对图形微调

                  continue;

                  //中垂线到*号的距离

                  dist = (int)Math.sqrt(radius*radius - (radius - 2*i)*(radius - 2*i));

                  while(j < radius - dist)//左半圆

                  {

                        System.out.print(" ");

                        j++;

                  }

                  System.out.print("*");

                  dist = radius + dist;

                  while(j < dist)//右半圆

                  {

                        System.out.print(" ");

                        j ++;

                  }

                  System.out.println("*");

                }

          }

评分

参与人数 1技术分 +1 收起 理由
zzkang0206 + 1

查看全部评分

回复 使用道具 举报
亲测楼上程序,最后少了个“}”,虽然不是很圆,还行吧。。。。。
回复 使用道具 举报
大家都很厉害   以后多多帮助 thanks
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马