lintcode 算法题 2316 · 判断三角形(Java 版)

该博客介绍了如何使用Java解决Lintcode上的2316题,即判断给定的三条边长是否能构成一个三角形。文章对比了作者自己的复杂实现和官方简洁的解决方案,强调了代码的简洁性和性能优化。
摘要由CSDN通过智能技术生成

题目:

给定三个整数 abc 代表三角形的三条边长,判断这三条边是否能组成一个三角形,当判断为是时,请通过 System.out.println 语句输出 Is a triangle,当判断为否时,请使用 System.out.println 语句输出 Not a triangle

三角形的概念是:任意两条边之和大于另一条边就可以为三角形

 然我自己写的代码还是复杂了,虽然能用但是if多了也影响性能,以此记录下

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // write your code here
        // read data from console
        
        // output the answer to the console according to 
        // the requirements of the question
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if ((a >= b && a >= c) && (c + b >= a)){
           
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值