给定半径为1.00的圆坐标的java数学计算 [英] java math calculation for coordinates of circle given radius of 1.00
问题描述
在我的一项任务中,我被要求编写一个程序来计算半径为1.0的圆上的点的(x,y)坐标。显示所有x值的y值输出,范围从1.00到负1.00,增量为0.1,并使用 printf
整齐地显示输出,其中所有x值垂直对齐,在所有x值的右侧,y值垂直对齐,如:
In one of my assignments, I am asked to write a program to calculate the (x, y) coordinates of points on a circle of radius 1.0. Display the output of y values for all x values ranging from 1.00 to negative 1.00 by increments of 0.1 and display the output neatly using printf
, where all the x values are aligned vertically and to the right of all the x values, the y values are aligned vertically like:
x1 y1
1.00 0.00
0.90 0.44
我知道如何使用毕达哥拉斯定理来计算y值,但是我不知道如何通过使用循环整齐地显示每个x和y值并使用 printf格式化
以下是我到目前为止的代码,任何帮助都会很大赞赏:
I know how to calculate the y values by using the Pythagorean theorem, but I don't know how to display every x and y values neatly by using a loop and formatting it with printf
Below is my code that I have so far, any help will be greatly appreciated:
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);
}
}
推荐答案
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);
}
}
循环中的代码可以根据你的需要调整它们需要。
The code within loop you can adjust them according to your need.
这篇关于给定半径为1.00的圆坐标的java数学计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!