- <pre name="code" class="java"></pre><br>
- <br>
- <p></p>
- <pre></pre>
- <pre name="code" class="java">package Exception;
- import java.util.*;
- public class Exception {
- void aa(int a,int b, int c)throws IllegalArgumentException {
- int []array = new int[]{a,b,c};
- Arrays.sort(array);//增排序,仍在数组里
- if(array[0]+array[1]>array[2]&&array[2]-array[0]<array[1])
- System.out.println("可以成为一个三角形,三条边按大小分别为"+a+","+b+","+c+"");
- else
- throw new IllegalArgumentException("不能组成三角形");
- }}
- </pre><br>
- <pre name="code" class="java">package Exception;
- import java.util.Scanner;
- public class Text {
- public static void main(String[] args) {
- // TODO 自动生成的方法存根
- try {
- System.out.println("输入三角形的三条边:");
- Scanner scanner=new Scanner(System.in);
- int a,b,c;
- a=scanner.nextInt();
- b=scanner.nextInt();
- c=scanner.nextInt();
- Exception ex=new Exception();
- ex.aa(a, b, c);
- }catch(IllegalArgumentException e) {
- e.printStackTrace();
- }
- }
- }
- </pre><br>
- <img src="http://img.blog.csdn.net/20171102194856882?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmljdG9yX2Zh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""><img src="http://img.blog.csdn.net/20171102195035360?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmljdG9yX2Zh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""><br>
- <p></p>