抛出异常

来源:互联网 发布:静安区人民法院知询 编辑:程序博客网 时间:2024/05/17 07:41
package com.yc;

import java.util.Scanner;
public class San {
        public static void main(String[]args){
            System.err.println("请输入三条边");
            Scanner sc=new Scanner(System.in);
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            isTriangle( a, b, c);
            
        }
        
        public static void isTriangle(int a,int b,int c){
                if(a<0||b<0||c<0){
                    throw new IllegalArgumentException("三条边不能为零");
                }if(a+b>c&&b+c>a&&c+a>b){
                    System.err.println("三角行面积"+"=a"+a+"=b"+b+"=c"+c);
                }else{
                    throw new IllegalArgumentException( a+" "+b+" "+c+""+"不构成三角行");
                }
}
}