Java 判断三条边能否组成一个三角形

Java 判断三条边能否组成一个三角形_第1张图片

public class TriangleWithException {
	public static void IllegalTriangleException(double side1,double side2,double side3){
	  if(side1+side2>side3&&side2+side3>side1&&side1+side3>side2) {
	   System.out.println("true");
	  }
	  else {
       System.out.println("false");
	  }
	 }

	public static void main(String[] args) {
		double a1;double a2;double a3;
	     System.out.println("Enter three edges:");
	     Scanner scanner=new Scanner(System.in);
	     a1=scanner.nextDouble();
	     a2=scanner.nextDouble();
	     a3=scanner.nextDouble();
         System.out.println("Can adges "+a1+", "+a2+" ,and "+a3+" form a triangle?");
	     IllegalTriangleException(a1,a2,a3);
	}
}

 

你可能感兴趣的:(java,开发语言,jvm)