先排序再根据前两个的平方和与第三个平方的大小关系判断

判断三角形类型

https://www.nowcoder.com/practice/1521dea0744c46ad8c31b0bd860625d0

import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int[] nums = new int[3];
            for (int i = 0; i < 3; i++) {
                nums[i] = sc.nextInt();
            }
            Arrays.sort(nums);
            int flag = nums[0] * nums[0] + nums[1] * nums[1] - nums[2] * nums[2];
            if (flag > 0) System.out.println("锐角三角形");
            else if (flag == 0) System.out.println("直角三角形");
            else System.out.println("钝角三角形");
        }
    }
}

全部评论

相关推荐

之前自己不懂事,投了字节,基本是自己第一次面试,一面就挂了
观水:前几天有个学化学的做前端,加上实习面了22次字节最后成功了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务