gpt4 book ai didi

java - 使用方法计算三角形的第三边

转载 作者:行者123 更新时间:2023-12-02 04:14:35 25 4
gpt4 key购买 nike

询问用户三角形的两条边,然后打印出通过方法计算出的第三条边的长度。编写一个方法,使用毕达哥拉斯定理求出第三条边的长度。

我是java新手,我对下面的代码感到很困惑,这可能离我很远......

import java.util.*;
public class Tri8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("Enter two numbers:");
int a = input.nextInt();
int b = input.nextInt();

System.out.println(pythagoraen(a, b));

}

//Method goes here
public static int pythagoraen(int x, int y) {
Math.pow(x, y);
int z = Math.sqrt(x, y);
Math.sqrt(x, y);

}
}

最佳答案

假设您打算使用 pythagorean theorem 找到直角三角形的斜边,需要返回其他两边的平方和的根:

public static double pythagoraen(int x, int y) {
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}

关于java - 使用方法计算三角形的第三边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33456779/

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