如果这样: 

private static int unsorted[];
for(int i = 1 ; i < 8 ; i ++ )
unsorted[i] = 1 ; 

是会报NullPointerException的,原因很简单,数组没有初始化!unsorted没有申请到内存空间,for(..)里面的i都不知道指向哪里。

可以这样声明同时初始化:

private static int unsorted[] = new int[8];

这样unsorted[]里面是8个0。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-09-18
相关资源
相似解决方案