A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

class Triangle {
        private int a;
        private int b;
        private int c;
        public Triangle(int a,int b,int c){
                /*if((a+b>c)&&(a+c>b)&&(b+c>a)){
                        this.a = a;
                        this.b = b;
                        this.c = c;
                } else {
                        System.out.println("对不起,亲,您输入的数字无法构成三角形!");
                        throw new RuntimeException("拜拜!");
                        //return ;                       
                }*/
                if((a+b<=c)||(a+c<=b)||(b+c<=a)){
                        System.out.println("对不起,亲,您输入的数字无法构成三角形!");
                        throw new RuntimeException("拜拜!");
                } else {
                        this.a = a;
                        this.b = b;
                        this.c = c;
                }
        }
        //获取三角形的周长
        public int getLength(){
                return a+b+c;
        }
        //获取三角形的面积
        public double getArea(){
                double temp = (a+b+c)/2.0;
                //double temp = (getLength())/2.0;
                return Math.sqrt((temp-a)*(temp-b)*(temp-c)*temp);
        }
        public static void main(String[] args){
                Triangle t = new Triangle(1,2,3);
                System.out.println("您输入的三角形的周长为:"+t.getLength()+",面积为:"+t.getArea());
        }
}

1 个回复

倒序浏览
。。。。注释和代码一样的光明正大骗字数
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马