題目

package ch5;
import java.io.*;
public class ch5_22
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader buf=new BufferedReader(in);
        int a=3,b=1,c=2,d=0;
        double e=0,ar=0;
        String sa,sb,sc,t;
        System.out.println("請輸入三個數字分別代表三角形三個邊長");
        sa=buf.readLine();
        a=Integer.parseInt(sa);
        sb=buf.readLine();
        b=Integer.parseInt(sb);
        sc=buf.readLine();
        c=Integer.parseInt(sc);
        if (a>b)
        {d=a;a=b;b=d;}
        if (b>c)
        {d=b;b=c;c=d;}
        if (a>b)
        {d=a;a=b;b=d;}
        if((a+b)<=c)
        {
            System.out.println("這無法成為一個三角形");
            return;
        }
        if ((a*a+b*b)>=c*c)
        {
            if((a*a+b*b)==c*c)
                t="直角三角形";
            else
                t="銳角三角形";
        }
        else
        {
            t="鈍角三角形";
        }
        e=0.5*(a+b+c);
        ar=Math.sqrt(e*(e-a)*(e-b)*(e-c));
        System.out.println("這是一個"+t+"面積是"+ar);
    }
}

==============

請輸入三個數字分別代表三角形三個邊長
19
10
10
這是一個鈍角三角形面積是29.663740492392392

 

創作者介紹
創作者 驢子的生活日記 的頭像
驢子

驢子的生活日記

驢子 發表在 痞客邦 留言(0) 人氣( 112 )