?? sanjiaoxing.java
字號:
import java.io.*;
public class sanjiaoxing{
public static void main(String arg[]){
int a=0,b=0,c=0;
String s;
try{//輸入三個數(將輸入的三個字符化為整數)
System.out.print("請輸入三角形三邊 ");
System.out.print("Enter a:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
a=Integer.parseInt(s);
System.out.print("Enter b:");
s=br.readLine();
b=Integer.parseInt(s);
System.out.print("Enter c:");
s=br.readLine();
c=Integer.parseInt(s);
System.out.println(a+" "+b+" "+c+" ");
}catch(IOException e){}
double S,p;
if((a+b)<=c&&(a+c)<=b&&(b+c)<=a&&(a-b)<=c&&(a-c)<=b&&
(b-c)<=a&&(b-a)<=c&&(c-a)<=b&&(c-b)<=a){//三邊不符合條件
int min;
if(a>b) min=b;//求最小邊
else min=a;
if(c>min) min=min;
else min=c; //求最小邊
p = (3*min)/ 2;
S=Math.sqrt(p * (p - min) *(p - min)*(p - min));
System.out.println("三角形的面積為 S="+S);
}
else{ p = (a + b +c) / 2;//三邊符合條件
S=Math.sqrt(p * (p - a) * (p- b) * (p- c));
System.out.println("三角形的面積為 S="+S);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -