在我的一项作业中,我被要求编写一个程序来计算半径为 1.0 的圆上的点的 (x, y) 坐标。以 0.1 为增量显示从 1.00 到负 1.00 的所有 x 值的 y 值输出,并使用 整齐地显示输出printf
,其中所有 x 值垂直对齐,所有 x 值右侧,y 值对齐垂直像:
x1 y1
1.00 0.00
0.90 0.44
我知道如何使用勾股定理计算 y 值,但我不知道如何通过使用循环和格式化来整齐地显示每个 x 和 y 值printf
下面是我到目前为止的代码,任何帮助都会不胜感激:
public class PointsOnACircleV1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// // create menu
// create title
System.out.println("Points on a circle of Radius 1.0");
// create x1 and y1
System.out.println(" x1 y1");
// create line
System.out.println("_________________________________________________");
// // display x values
// loop?
// // perform calculation
// radius
double radius = 1.00;
// x value
double x = 1.00;
// calculate y value
double y = Math.pow(radius, 2) - Math.pow(x, 2);
}
}