lingcheng7777

数组只有5个元素,却去访问第10个元素

int[] scores = new int[]{1,2,3,4,5};

System.out.println(scores[10]);

执行结果:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10

at javase.base.TestArea.main(TestArea.java:16)

注意这种错误很隐秘,编译时不报错,运行时才会报错,所以开发时一定要注意其取值。

分类:

技术点:

相关文章:

  • 2021-11-14
  • 2021-10-14
  • 2021-09-14
  • 2021-06-27
  • 2021-11-04
  • 2021-10-14
猜你喜欢
  • 2021-11-14
  • 2021-11-04
  • 2021-11-04
  • 2021-11-04
  • 2021-08-03
  • 2021-11-04
  • 2021-11-04
相关资源
相似解决方案