我需要包含圆形区域公式的面积方法,以获取由计算距离的其他区域方法找到的半径...因此,其中一个面积方法计算了距离/半径我希望将答案用于圆形区域的面积方法半径。
public class AreaCircle {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
double x1, x2, y1, y2, xc, yc;
System.out.println("x1: ");
x1 = reader.nextInt();
System.out.println("x2: ");
x2 = reader.nextInt();
System.out.println("y1: ");
y1 = reader.nextInt();
System.out.println("y2: ");
y2 = reader.nextInt();
double distance = area(x1, x2, y1, y2);
System.out.println("The radius of the circle is: ");
System.out.println(distance);
double answer = area(distance);
System.out.println("The area of the circle is: ");
System.out.println(answer);
}
public static double area (double distance) {
double areaCircle;
double powRadius;
double radius = distance;
powRadius = Math.pow(radius, 2);
areaCircle = (Math.PI *(powRadius));
return areaCircle;
}
public static double area (double x1, double x2, double y1, double y2) {
double dx = x2 - x1;
double dy = y2 - y1;
double dsquared = dx*dx + dy*dy;
double distance = Math.sqrt (dsquared);
return distance;
}
答案 0 :(得分:0)
您需要做的是为area()
方法提供一个半径为
像这样:
public static double area(double radius) {
//same as before
double areaCircle;
double powRadius;
powRadius = Math.pow(radius, 2);
areaCircle = (Math.PI *(powRadius));
return areaCircle;
}
同时重命名您的其他area()
方法。它应该被称为returnDistance
。