我有一个学校的作业,我必须创建一个程序来计算给定四个点的圆的面积,但是当我在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));

关于java - Java编码区域圆,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32953049/

10-10 10:30