三角形判定条件:任意俩边之和大于第三边,任意俩边之差小于第三边。
Scanner scanner = new Scanner(System.in);
System.out.println("请输入三角形的三条边:");
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
if (a > b) {
if (b > c) {
if (b + c > a && a - c < b) {
System.out.println("周长是:" + (a + b + c));
} else {
System.out.println("非法三角形");
}
} else {
if (a > c) {
if (b + c > a && a - b < c) {
System.out.println("周长是:" + (a + b + c));
} else {
System.out.println("非法三角形");
}
}
}
} else {
if (b > c) {
if (a + c > b && b - c < a) {
System.out.println("周长是:" + (a + b + c));
} else {
System.out.println("非法三角形");
}
} else {
if (a + b > c && c - a < b) {
System.out.println("周长是:" + (a + b + c));
} else {
System.out.println("非法三角形");
}
}
}