1. 正三角形(三邊等長)
2. 等腰三角形(兩邊等長)
3. 不規則三角形(三邊等長)
4. 無法構成三角形(任意兩邊和小於或等於第三邊)
import java.util.Scanner;
public class C1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//輸入三角形三邊長
System.out.println("請輸入三角形的第一個邊長");
double a = input.nextDouble();
System.out.println("請輸入三角形的第二個邊長");
double b = input.nextDouble();
System.out.println("請輸入三角形的第三個邊長");
double c = input.nextDouble();
//判斷三角形種類
if(a + b <= c || a + c <= b || c + b <= a )
{
System.out.println("輸入三邊長,無法構成三角形");
}
else if(a == b && b == c && c == a)
{
System.out.println("正三角形");
}
else if(a == b || b == c || c == a)
{
System.out.println("等腰三角形");
}
else
{
System.out.println("不規則三角形");
}
}
}
沒有留言:
張貼留言