該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
就下面這個程序 輸入其他的數字都可以算出面積 但是當輸入3,4,6時 計算出面積為零 求吧友指出錯誤在哪
package javaapplication17;
import java.util.Scanner;
public class JavaApplication17 {
public static void main(String[] args) {
int a, b, c;
Scanner s = new Scanner(System.in);
try {
System.out.print("請輸入三角形第1個邊長(回車繼續):");
a = s.nextInt();
System.out.print("請輸入三角形第2個邊長(回車繼續):");
b = s.nextInt();
System.out.print("請輸入三角形第3個邊長(回車繼續):");
c = s.nextInt();
}
catch (Exception ex) {
System.out.println("輸入的不是數字");
return;
}
if (a + b > c && b + c > a && a + c > b) {
System.out.println("可以構成三角形");
double d = (a + b + c) / 2;
double e = Math.sqrt(d * (d - a) * (d - b) * (d - c));
System.out.println("面積為:" + e);
}
else { System.out.println("不可以構成三角形!");
}}}