代码如下: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("@@");
输出会接近圆形了