Java三角形状信息录入

定义一个三角形类——triangle,提供属性:边长 ,定义方法:计算周长,判断是否为等腰三角形,输出最长边长 。

输入:

第一行三个数,表示各边长

第二行为一个数n,表示查询次数,接下来为n行查询

查询类型:1:输出周长,2:输出是否是等腰三角形(如果是等边三角形,则输出等边三角形,如果三边不等输出否,否则输出是)3:输出最长边长

输入:

2 2 2

3

1

2

3

输出:

6

等边三角形

2

输入用例:

2 2 2 3 1 2 3

输出用例:

6 等边三角形 2

输入用例:

1 1 2 1 2

输出用例:

输入用例:

5 4 3 2 1 3

输出用例:

12 5

import java.util.*;

public class Main{

    public static void main(String[] args) {

        // your code

        Scanner sc=new Scanner(System.in);

        int a=sc.nextInt();

        int b=sc.nextInt();

        int c=sc.nextInt();

        int time=sc.nextInt();

        San san=new San(a,b,c);

        

        for(int i=1;i<=time;i++){

          int d=sc.nextInt();

          if(1==d){

            System.out.println(san.zhouc());

          }else if(2==d){

            if(san.deng()==1){

              System.out.println("等边三角形");

            }else if(san.deng()==2){

              System.out.println("是");

            }else if(san.deng()==3){

              System.out.println("否");

            }

          }else if(3==d){

            System.out.println(san.big());

          }

        }

    }

}

class San{

    public int a;

    int b;

    int c;

    San(int a,int b,int c){

      this.a=a;

      this.b=b;

      this.c=c;

    }

    int zhouc(){

      return a+b+c;

    }

    int big(){

      int temp = (a>b) ? a : b;

      int max = (temp>c) ? temp : c;

      return max;

    }

    int deng(){

      if(a==b&&a==c&&b==c){

        return 1;

      }if(a==b||a==c||b==c) {

        return 2;

      }else{

        return 3;

      }

      

    }

}

import java.util.*;

public class Main{

    public static void main(String[] args) {

        // your code

        Scanner sc=new Scanner(System.in);

        int a=sc.nextInt();

        int b=sc.nextInt();

        int c=sc.nextInt();

        int time=sc.nextInt();

        San san=new San(a,b,c);

        

        for(int i=1;i<=time;i++){

          int d=sc.nextInt();

          if(1==d){

            System.out.println(san.zhouc());

          }else if(2==d){

            if(san.deng()==1){

              System.out.println("等边三角形");

            }else if(san.deng()==2){

              System.out.println("是");

            }else if(san.deng()==3){

              System.out.println("否");

            }

          }else if(3==d){

            System.out.println(san.big());

          }

        }

    }

}



class San{

    public int a;

    int b;

    int c;

    San(int a,int b,int c){

      this.a=a;

      this.b=b;

      this.c=c;

    }

    int zhouc(){

      return a+b+c;

    }

    int big(){

      int temp = (a>b) ? a : b;

      int max = (temp>c) ? temp : c;

      return max;

    }

    int deng(){

      if(a==b&&a==c&&b==c){

        return 1;

      }if(a==b||a==c||b==c) {

        return 2;

      }else{

        return 3;

      }

      

    }

}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值