为什么我在运行下面的代码块时没有打印到屏幕上? 它不准确地打印它,看起来像是我在扫描坐标时做错的事情。打印圆圈到屏幕
public class Question2 {
public static void main(String[] args) {
DrawMeACircle(3, 3, 3); // should print to the screen an ellipse looking circle
}
public static void DrawMeACircle(double posX, double posY, double radius) {
double xaxis = 20; // scanning the coordinates
double yaxis = 20; // " "
for (double x = 0; x < xaxis; x++) {
for (double y = 0; y < yaxis; y++) {
//using the formula for a cicrle
double a = Math.abs((posX - x) * (posX - x));
double b = Math.abs((posY - y) * (posY - y));
double c = Math.abs(a + b);
double d = Math.abs(radius * radius);
// checking if the formula stands correct at each coordinate scanned
if (c == d) {
System.out.print('#');
}
else {
System.out.print(' ');
}
}
System.out.println();
}
}
}
它打印什么? –
什么不起作用?是不是正在绘制,还是印刷的东西看起来不像是一个圆圈? – imulsion
这似乎工作,但它是一个粗糙的表示,因为你打印到控制台 – Sionnach733