判斷輸入三邊能否構成三角形
阿新 • • 發佈:2019-01-04
package com.mc.Demo;
import java.util.Scanner;
public class TestDemo {
public static void main(String[] args) {
// new TestDemo();
Scanner sc = new Scanner(System.in);
System.out.println("請輸入三角形的三邊:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
// 判斷是否三角形
if (a + b >= c && a + c >= b && b + c >= a) {
// 判斷三角形型別
if (a == b && b == c) {
System.out.println("這是等邊三角形");
} else if (a == b || a == c || b == c) {
System.out .println("這是等腰三角形");
} else if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b) {
System.out.println("這是直角三角形");
} else if (a * a + b * b > c * c || a * a + c * c > b * b || b * b + c * c > a * a) {
System.out .println("這是銳角三角形");
} else if (a * a + b * b < c * c || a * a + c * c < b * b || b * b + c * c < a * a) {
System.out.println("這是鈍角三角形");
}
} else {
System.out.println("這不是三角形");
}
}
}