public class Triangle {
public boolean isTriangle(int a,int b, int c){
boolean flag=false;
if ((a+b>c&&a+c>b&&c+b>a)&&(Math.abs(a-b)<c&&Math.abs(a-c)<b&&Math.abs(c-b)<a)){
flag=true;
shape(a,b,c);
}else {
System.out.println("这不能构成三角形。");
}
return flag;
}
public String shape(int a,int b, int c){
String shape=null;
if (a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b){
shape="直角三角形";
System.out.println("这是"+shape);
}else if (a*a>b*b+c*c||b*b>a*a+c*c||c*c>a*a+b*b){
shape="钝角三角形";
System.out.println("这是"+shape);
}else if (a*a<b*b+c*c||b*b<a*a+c*c||c*c<a*a+b*b){
shape="锐角三角形";
System.out.println("这是"+shape);
}
return shape;
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int a;
int b;
int c;
String choice;
Scanner input=new Scanner(System.in);
do {
Triangle tt=new Triangle();
System.out.print("请输入第一条边:");
a=input.nextInt();
System.out.print("请输入第二条边:");
b=input.nextInt();
System.out.print("请输入第三条边:");
c=input.nextInt();
tt.isTriangle(a,b,c);
System.out.print("继续吗?(y/n):");
choice=input.next();
if (choice.equals("n")){
System.out.println("谢谢使用!");
break;
}
}while (choice.equals("y"));
}
}