如何从 main 方法中调用第一个区域方法?

How do I call the first area method from the main method?

我需要包含圆面积公式的面积方法,以采用计算距离的其他面积方法找到的半径...因此其中一种面积方法计算了 distance/radius 然后我希望在圆面积的面积方法的半径中使用该答案。

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;
}

您需要做的是为您的 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.