面向对象的第一次pta作业第四题:判断三角形类型
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner triangle = new Scanner(System.in); double a=0,b=0,c=0; a=triangle.nextDouble(); b=triangle.nextDouble(); c=triangle.nextDouble(); if(a<1||a>200||b<1||b>200||c<1||c>200) System.out.println("Wrong Format"); else if((a+b<=c)||(b+c<=a)||(a+c<=b)) System.out.println("Not a triangle"); else if((a==b)||(b==c)||(a==c)) { if((a==b)&&(b==c)) System.out.println("Equilateral triangle"); else if((Math.abs(c*c-a*a-b*b)<=0.00001)||(Math.abs(a*a-c*c-b*b)<=0.00001)||(Math.abs(b*b-a*a-c*c)<=0.00001)) System.out.println("Isosceles right-angled triangle"); else System.out.println("Isosceles triangle"); } else if((a*a+b*b==c*c)||(b*b+c*c==a*a)||(a*a+c*c==b*b)) System.out.println("Right-angled triangle"); else System.out.println("General triangle"); } }