标签:
//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()); } } }
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"); } }
public class IllegalTriangleException extends Exception{ public IllegalTriangleException(String s) { super(s); } }
标签:
原文地址:http://www.cnblogs.com/wanjiang/p/5568061.html