谁帮我看看这个数组越界的异常,怎么处理,有日志文件

发布于2022-06-22 15:00:09
1个回答
admin
网友回答2022-06-22
int b[] = new int [5]; Scanner s = new Scanner(System.in); try { for(int i = 0; s.hasNextInt(); ++i) b[i] = s.nextInt(); } catch(ArrayIndexOutOfBoundsException e) { System.out.print("数组越界! "); System.out.println("下标: " + e.getMessage()); } for(int i = 0; i < b.length; ++i) System.out.print(b[i] + " ");

回到
顶部