Board logo

標題: TQC208 [打印本頁]

作者: ray    時間: 2012-3-3 20:15     標題: TQC208

public class TQC208
{
  public static void main(String args[]){
    double arg1,arg2,arg3;
    if(args.length == 3) { //請在此撰寫判斷三角形之程式
      try{
        arg1=Double.parseDouble(args[0]);
        arg2=Double.parseDouble(args[1]);
        arg3=Double.parseDouble(args[2]);
        TQC208 ta=new TQC208();
        ta.identify(arg1,arg2,arg3);
      }catch(NumberFormatException e){
        System.out.println("您的輸入中有無法處理的非數值參數 !");
      }
    }else{
        //請在此撰寫判斷三角形錯誤的資訊
      System.out.println("參數數目錯誤:三角形邊長應有三個參數");
      System.exit(0);
    }
  }
  public void identify(double a, double b, double c){
    double tmp;
   //將a,b,c由小至大排列 再進行判斷
   boolean ra;
   if( c < b ){
      tmp = b;
      b = c;
      c = tmp;
   }
   if( b < a ){
      tmp = a;
      a = b;
      b = tmp;
   }
   if( c < b ){
      tmp = b;
      b = c;
      c = tmp;
   }
   if( (Math.pow(a,2)+Math.pow(b,2))==Math.pow(c,2)){
      ra = true;
   }else{
      ra=false;
   }

   if( (a+b<=c)||(a*b*c==0)||(a<0)||(b<0)||(c<0) ){ //請在此撰寫判斷三角形之程式
      System.out.println("您輸入的並非一個三角形的邊長資料 !");
    }else if((a==b)&&(b==c)){ //請在此撰寫判斷三角形之程式
      System.out.println("您所輸入的是一個等邊三角形的邊長資料 !");
    }else if((a==b)||(b==c)){ //請在此撰寫判斷三角形之程式
        if( ra==true ){
             //請此在撰寫判斷三角形之程式

          System.out.println("您所輸入的是一個等腰直角三角形的邊長資料 !");
        }else{
          System.out.println("您所輸入的是一個等腰三角形的邊長資料 !");
        }
    }else if(ra==true){
             //請在此撰寫判斷三角形之程式
      System.out.println("您所輸入的是一個直角三角形的邊長資料 !");
    }else if((Math.pow(a,2)+Math.pow(b,2))<Math.pow(c,2)){
        //請在此撰寫判斷三角形之程式

      System.out.println("您所輸入的是一個鈍角三角形的邊長資料 !");
    }else{
      System.out.println("您所輸入的是一個銳角三角形的邊長資料 !");
    }
  }
}




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2