Java 编码区Circle

Java Coding areaCircle

我有一个学校作业,我必须创建一个程序来计算给定四个点的圆的面积,但是当我在 main 中调用方法 areaCircle 时,没有任何反应。它不计算面积。

public static void main(String[] args) {
    Scanner reader;
    reader = new Scanner(System.in);
    System.out.println("Enter the coordinates of a point on the outside of a circle.");
    System.out.println("x-coordinate: ");
    int x1 = reader.nextInt();
    System.out.println("y-coordinate: ");
    int y1 = reader.nextInt();
    System.out.println("Enter the center point of the circle.");
    System.out.println("x-coordinate: ");
    int x2 = reader.nextInt();
    System.out.println("y-coordinate:");
    int y2 = reader.nextInt();
    areaCircle(x1, y1, x2, y2);
}

public static double distance(int x1, int y1, int x2, int y2) {
    double dx = x2 - x1;
    double dy = y2 - y1;
    double dsquared = dx * dx + dy * dy;
    double result = Math.sqrt(dsquared);
    return result;
}

public static double areaCircle(int radius, double area) {
    area = Math.PI * (radius * radius);
    return area;
}

public static double areaCircle(int x1, int x2, int y1, int y2) {
    double radius = distance(x1, y1, x2, y2);
    double area = Math.PI * (radius * radius);
    return area;
}

您只需要打印结果,此时您只是在计算。

而不是

areaCircle (x1, y1, x2, y2);

System.out.println("The area is: " + areaCircle (x1, y1, x2, y2));