207 三角形邊長判斷

import java.util.*;
public class JPA207 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    static void test() {
double a,b,c;
System.out.println("請輸入三個整數:");
a=keyboard.nextDouble();
b=keyboard.nextDouble();
c=keyboard.nextDouble();

double x[]={a,b,c};
  Arrays.sort(x);
  a=x[0];
b=x[1];
  c=x[2];//c is max

if((a+b<=c)||a<=0||b<=0||c<=0){
System.out.println("不可以構成三角形");
}
else if((Math.pow(a,2)+Math.pow(b,2))==Math.pow(c,2)){
System.out.println("直角三角形");
}
else if((Math.pow(a,2)+Math.pow(b,2))<Math.pow(c,2)){
System.out.println("頓角三角形");
}
else{
System.out.println("銳角三角形");
}

    }
}

沒有留言:

張貼留言