package com.Jt; import java.util.Scanner; public class Triangle { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("请输入"+"a"+"\t"+"b"+"\t"+"c"); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); try { sanjiao(a, b, c); } catch (IllegalArgumentException e) { e.printStackTrace(); } } public static void sanjiao(int a, int b, int c) throws IllegalArgumentException{ if (a + b > c && a + c > b && b + c > a) { System.out.println("构成三角形" + a + " " + b + " " + c); } else { throw new IllegalArgumentException("不能构成三角形"+ a + " " + b + " " + c); } } }
从命令行得到5个整数,放入一整型数组,然后打印输出,要求:如果输入数据pi为整数,要捕获Integer.parseInt()产生的异常,显示“请输入整数”,捕获输入参数pi足5个的异常(数组越界)。显
最新推荐文章于 2023-11-24 22:42:02 发布