題目
輸入三角形三邊長求面積(假定該三角形成立)
package ch4;
import java.io.*;
public class ch4_11_3
{
public static void main(String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
int sideA,sideB,sideC,d;
double ar;
String strsideA,strsideB,strsideC;
System.out.print("請在這邊輸入邊長:");
strsideA=buf.readLine();
sideA=Integer.parseInt(strsideA);
System.out.println(sideA);
System.out.print("請在這邊輸入第二邊長:");
strsideB=buf.readLine();
sideB=Integer.parseInt(strsideB);
System.out.println(sideB);
System.out.print("請在這邊輸入第三邊長:");
strsideC=buf.readLine();
sideC=Integer.parseInt(strsideC);
System.out.println(sideC);
d=(sideA+sideB+sideC)/2;
ar=Math.pow((d*(d-sideA)*(d-sideB)*(d-sideC)),0.5);
System.out.println("三角形面積為"+ar);
}
}
留言列表