久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      java判斷是否是三角形方法介紹

      java判斷是否是三角形方法介紹

      寫(xiě)一個(gè)方法void triangle(int a,int b,int c),判斷三個(gè)參數(shù)是否能構(gòu)成一個(gè)三角形。如果不能則拋出異常IllegalArgumentException,顯示異常信息:a,b,c “不能構(gòu)成三角形”;如果可以構(gòu)成則顯示三角形三個(gè)邊長(zhǎng)。在主方法中得到命令行輸入的三個(gè)整數(shù),調(diào)用此方法,并捕獲異常。

      a<b<c

      兩邊之和大于第三邊:a+b>c

      兩邊之差小于第三邊:c-a<a

      import java.util.Arrays;   import java.util.Scanner;      public class 三角形判斷 {          public static int[] side;       public static void main(String[] args) {           side=new int[3];           Scanner input=new Scanner(System.in);                  try {               side[0]=input.nextInt();               side[1]=input.nextInt();               side[2]=input.nextInt();               Arrays.sort(side);               triangle(side[0],side[1],side[2]);           } catch (IllegalArgumentException e) {               e.getMessage();               e.printStackTrace();           }catch (Exception e) {               e.printStackTrace();           }finally {               input.close();           }       }              public static void triangle(int a,int b,int c)throws Exception{           if((a+b>c)&&(a-b<c))               System.out.println("可以構(gòu)成三角形");           else               throw new IllegalArgumentException("三條邊不能構(gòu)成三角形");       }      }

      運(yùn)行結(jié)果:

      java判斷是否是三角形方法介紹

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)