gpt4 book ai didi

Java 编码区Circle

转载 作者:行者123 更新时间:2023-11-30 03:14:28 26 4
gpt4 key购买 nike

我有一个学校作业,我必须创建一个程序来计算给定四个点的圆的面积,但是当我在 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 编码区Circle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32953049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com