在java程序中编写一个含有分母为零及数组越界的异常处理程序,可以提供以下代码嘛,谢谢
1条回答 默认 最新
CSDN专家-Fay 2021-06-22 08:39关注分母为零及数组越界 都有相应的异常可以捕获,提示下就行了
如有帮助请在我的回答上点个【采纳】
public class Test { public static void main(String[] args) { try { int i = 5, j = 0; System.out.println(i / j); } catch (ArithmeticException e) { System.out.println("分母不能为0!"); } try { int[] a=new int[]{1,2,3,4,5}; System.out.println(a[5]); }catch (IndexOutOfBoundsException e) { System.out.println("数组越界了!"); } } }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用