1.编写一程序,声明一个数组,int a[ ]={1,2,3,4},循环输出该数组中的每个数,循环变量i=0,i<5,处理数组下标越界产生的异常。-
6条回答 默认 最新
- threenewbee 2018-10-17 04:16关注
void main() throws IndexOutOfBoundException { try { int[] a={1,2,3,4}; for (int i = 0; i < 5; i++) System.out.println(a[i]); } catch (IndexOutOfBoundException ex) { System.out.println("越界"); } }
手工写的,仅供参考
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用