日期:2014-05-20 浏览次数:21062 次
import java.lang.Math;
import java.io.*;
/**
* 绘制近似圆
*/
public class Circle
{
/**
* 圆的半径
* @param r:圆的的半径
*/
private double r;
public double getR()
{
return r;
}
public void setR(double R)
{
r = R;
}
public void draw()
{
System.out.print("请输入半径");
try
{
//读入半径
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
r = Double.parseDouble(br.readLine()) ;
}
catch(IOException e)
{
e.toString();
}
int x1,x2,y;
String str;
for (int i = 0; i <= 12; i++)
{
if (i == 0)
{
y = Math.round((float)(r-Math.cos(Math.toRadians(15*i))*r));
}else{
y = Math.round((float)(r-Math.cos(Math.toRadians(15*i))*r))-Math.round((float)(r-Math.cos(Math.toRadians(15*i-15))*r));
}
x1 = Math.round((float)(r-Math.sin(Math.toRadians(15*i))*r));
x2 = Math.round((float)(r+Math.sin(Math.toRadians(15*i))*r));
str = "";
if (i != 0 && i != 12)
{
if (y == 0)
{
continue;
}
}else if(i == 12){
System.out.println("");
}
for (int j=0; j <y; j++)
{
System.out.println("");
}
for (int k=0; k < x1; k++)
{
str+=" ";
}
str+="*";
for (int k=0; k < x2-x1; k++)
{
str+=" ";
}
str+="*";
System.out.print(str+"角度"+15*i+"y="+y+" x1="+x1+" x2="+x2);
}
System.out.println("");
draw();
}
public static void main(String args[])
{
new Circle().draw();
}
}