import java.util.Scanner;
class Demo_DrawCircle
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入半径:");
int input = sc.nextInt();
//String input01 = sc.nextLine();
String input01 = input+"";
if(checkInput(input01))
{
/*************** 画圆方法 ***************/
int R = input;
drawCir(R);
}
System.out.println("程序已退出……");
}
public static void drawCir(int R){
for(int i=0;i<(R-2);i++)
{
int m = (R-i);
int n = (int)Math.sqrt(Math.pow(R,2)-Math.pow(m,2));
//System.out.println(n);
int x = R-n;
//System.out.println(x);
pCircle01(R,x);
}
for(int i=(R-2);i>=0;i--)
{
int m = (R-i);
int n = (int)Math.sqrt(Math.pow(R,2)-Math.pow(m,2));
//System.out.println(n);
int x = R-n;
//System.out.println(x);
pCircle01(R,x);
}
}
public static void pCircle01(int R,int x)//画圆;
{
for(int i=0;i<(2*R);i++)
{
if(i == x|i == (2*R-x))
{ pStar(); }
else
{ pNull(); }
} System.out.println("");
}
public static void pNull()//画空格;
{ System.out.print(" "); }
public static void pStar()//画星星;
{ System.out.print("☆"); }
public static boolean checkInput(String input)//检查输入是否正确;
{
for(int i=0;i<input.length();i++)
{
char each = input.charAt(i);
if(each>'9'||each<'0')
{ System.out.println("您输入的数字不规范,请重试!");
return false; }
}
return true;
}
}
|
|