当前位置: 代码迷 >> J2SE >> 朋友进来帮忙看看多谢!让用*画一个圆,小弟我画出来的为啥是椭圆
  详细解决方案

朋友进来帮忙看看多谢!让用*画一个圆,小弟我画出来的为啥是椭圆

热度:579   发布时间:2013-02-25 00:00:00.0
朋友进来帮忙看看谢谢!让用*画一个圆,我画出来的为啥是椭圆
代码如下:public class Point {
public int x;
public int y;

public Point(){

}
public Point(int x,int y){
this.x = x;
this.y = y;
}
public double distance(double x,double y){
return Math.sqrt(Math.pow(x-this.x, 2)+Math.pow(y-this.y, 2));
}
public double distance(Point p){
return distance(p.x,p.y);
}





public class Circle extends Shape {
public double r;

public Circle(){

}
public Circle(int x,int y,int r){
super.location = new Point(x,y);
this.r = r;

}
public boolean contains(double x,double y){
return super.location.distance(x, y)<r;
}


}




public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Circle a = new Circle(5,5,4);



for(double i = 0;i<30;i+=0.1){
for(double j = 0;j<30;j+=0.1){
if(a.contains(j,i)){
System.out.print("@");
}else{
System.out.print(" ");
}

}System.out.println();
}

}

}
大神帮忙看看谢谢!

------解决方案--------------------------------------------------------
控制台中每个字符的长宽比例不是1:1的,其实是个长方形的,所以输出的不会是圆形。
如果你把 System.out.print("@")
改成System.out.print("@@");
输出会接近圆形了

  相关解决方案