做一个含有分母为零及数组越界的异常处理程序

在java程序中编写一个含有分母为零及数组越界的异常处理程序,可以提供以下代码嘛,谢谢

分母为零及数组越界 都有相应的异常可以捕获,提示下就行了

 

如有帮助请在我的回答上点个【采纳】

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("数组越界了!");
		}
	}
}