zoukankan      html  css  js  c++  java
  • Java自定义异常

    package cn.Douzi.Lab7_4;
    
    
    public class Triangle {
        
        int a, b, c;
    
        public Triangle(int a, int b, int c) {
            super();
            this.a = a;
            this.b = b;
            this.c = c;
        }
        
        int getArea() throws Exception {
            
            if (a + b <= c || a + c <= b || b + c <= a) {
                throw new IllegalArgumentException("两边之和大于第三边");
            }
            else {
                int p = (a + b + c) / 2;
                return (int)Math.sqrt(p * (p - a) * (p - b) * (p - c));
            }
            
        }
        
    }
    package cn.Douzi.Lab7_4;
    
    public class Lab4 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            Triangle tri = new Triangle(5, 1, 4);
            
            try {
                int area;
                area = tri.getArea();
                System.out.println("面积: " + area);            
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                
            }
        }
    
    }
  • 相关阅读:
    sql number类型和varchar2类型
    B
    E
    D
    B
    A
    第三课 选区
    第二课 新建文件与图层
    第一课 界面认识
    CSS命名规则
  • 原文地址:https://www.cnblogs.com/douzujun/p/6841322.html
Copyright © 2011-2022 走看看