码迷,mamicode.com
首页 > 其他好文 > 详细

13.5

时间:2016-06-07 20:47:30      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享
//13.5
import java.util.Scanner;
import java.awt.*;

import java.util.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class Test
{    
    public static void main(String[] args) {
        double s1 = 0,s2 = 0,s3 = 0;
        Scanner input = new Scanner(System.in);
        s1 = input.nextDouble();
        s2 = input.nextDouble();
        s3 = input.nextDouble();
        try {Triangle t1 = new Triangle(s1,s2,s3);}
        catch(IllegalTriangleException ex){
            System.out.println(ex.getMessage());
        }
      }
}
Test.java
技术分享
public class Triangle {
    private double side1,side2,side3;
    
    public Triangle(double side1,double side2,double side3)
    throws IllegalTriangleException{
        if((side1+side2>side3)&&(side1+side3>side2)&&(side2+side3>side1))
            System.out.println("valid sides");
        else
            throw new IllegalTriangleException("invalid sides");        
    }    
}
Triangle.java
技术分享
public class IllegalTriangleException extends Exception{
    public IllegalTriangleException(String s)
    {
        super(s);
    }
}
IllegalTriangleException.java

 

13.5

标签:

原文地址:http://www.cnblogs.com/wanjiang/p/5568061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!