给定半径为1.00的圆坐标的java数学计算
在我的一项作业中,我被要求编写一个程序来计算半径为1.0的圆上点的x,y坐标。以0.1的增量显示从1.00到负1.00的所有x值的y值输出,并使用printf整齐地显示输出,其中所有x值垂直对齐,在所有x值的右侧,y值垂直对齐,如下所示:给定半径为1.00的圆坐标的java数学计算,java,math,geometry,Java,Math,Geometry,在我的一项作业中,我被要求编写一个程序来计算半径为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值,但我不知道如何使用循环和printf格式整齐地显示每个x和y值。以下是我迄今为止的代码,非常感谢您的帮助: public class PointsOnACi
x1 y1
1.00 0.00
0.90 0.44
我知道如何使用毕达哥拉斯定理计算y值,但我不知道如何使用循环和printf格式整齐地显示每个x和y值。以下是我迄今为止的代码,非常感谢您的帮助:
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);
}
}
这应该让你开始。如果您不理解System.out.print语句括号内的部分,我建议您查找System.out.print的功能、格式说明符和转义字符。那你应该准备好了
public static void main(String[] args) {
double radius = 1.00;
double x , y ;
for ( x=-1.0 ; x<=1.0; x+=0.2 ) {
y = Math.sqrt(radius - Math.pow(x,2)) ;
System.out.printf("\n" + x +" "+ y);
}
}
这应该让你开始。如果您不理解System.out.print语句括号内的部分,我建议您查找System.out.print的功能、格式说明符和转义字符。那你应该准备好了
public static void main(String[] args) {
double radius = 1.00;
double x , y ;
for ( x=-1.0 ; x<=1.0; x+=0.2 ) {
y = Math.sqrt(radius - Math.pow(x,2)) ;
System.out.printf("\n" + x +" "+ y);
}
}
循环中的代码可以根据需要进行调整
public class PointsOnACircleV1
{
public static void main (String [] args)
{
double r = 1; //radius initialized to one
double x = 1; // x coordinate initialized to one, could be anything
double y = 0.0; // y coordinate is dependent so left at 0.
//output
System.out.println("\tPoints on a Circle of Radius 1.0");
System.out.printf("\t%6s%6s%12s%7s\n", "x1", "y1", "x1", "y2");
System.out.println("--------------------------------------------");
//for loop to decrement values from the initialized x coordinate to the
//end of the diameter, radius is 1 so diameter is 2 so 1 to -1.
for(x = 1; x >= -1; x -= .1)
{
y = Math.sqrt(Math.pow(r,2) - Math.pow(x,2)); //pythagorean theorem to achieve y value.
System.out.printf("\t%6.2f%7.2f%12.2f%8.2f\n", x, y, x, -y); //output, -y to get values
//for the other 1/2 of the circle
}
}
循环中的代码可以根据需要进行调整
public class PointsOnACircleV1
{
public static void main (String [] args)
{
double r = 1; //radius initialized to one
double x = 1; // x coordinate initialized to one, could be anything
double y = 0.0; // y coordinate is dependent so left at 0.
//output
System.out.println("\tPoints on a Circle of Radius 1.0");
System.out.printf("\t%6s%6s%12s%7s\n", "x1", "y1", "x1", "y2");
System.out.println("--------------------------------------------");
//for loop to decrement values from the initialized x coordinate to the
//end of the diameter, radius is 1 so diameter is 2 so 1 to -1.
for(x = 1; x >= -1; x -= .1)
{
y = Math.sqrt(Math.pow(r,2) - Math.pow(x,2)); //pythagorean theorem to achieve y value.
System.out.printf("\t%6.2f%7.2f%12.2f%8.2f\n", x, y, x, -y); //output, -y to get values
//for the other 1/2 of the circle
}
}
}
}您的y值不正确。无论如何,google for loops in java for for and while,在这种情况下,最好是Former如果忽略以下事实,即对于每个2点的xexcept,除非您想对圆中是否真的有0和-0值进行哲学思考,否则会产生2个y值?您的y值不正确。无论如何,在java中google for loops for for for and while,在这种情况下,最好是Formera。如果你忽略了一个事实,即对于每个2点的xexcept,除非你想对一个圆中是否真的有0和-0值进行哲学思考,否则会产生2Y值?我想你会在这里使用浮点表示法。我认为从0到19循环更好,并将其映射到相应的x值。实际上这很好。但是为什么不是10,-10和-1。使用/10.0。只需从所有内容中减去一个0。但这是一样的+1只是因为他指定他的双精度应为1.00。如果我觉得百位意义重大,我会这样做。我想你会在这里用浮点表示法。我认为从0到19循环更好,并将其映射到相应的x值。实际上这很好。但是为什么不是10,-10和-1。使用/10.0。只需从所有内容中减去一个0。但这是一样的+1只是因为他指定他的双精度应为1.00。如果我觉得这几百个地方意义重大,我会这样做的。如果你也添加一些关于代码的解释,而不是具体的逐行注释,但是一个简短的描述就足够了,如果你也添加一些关于代码的解释,而不是具体的逐行注释,但是一个简短的描述就足够了,那就更好了