how to take large size array in java

后端 未结 6 1178
醉话见心
醉话见心 2021-01-26 07:05

i am new to java and i want to take large input size array in java. but in gives me some Runtime Error - NZEC, I don\'t know about it and i also did some research on this error

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 07:34

    An array index cannot be specified with a long as you have done but only with an int as the array size is limited to Integer max value

    But in your case it should not be a problem as Integer max value is 2^31-1. (more than 2 billions) and you requirement is inferior :10^9 (1 billion).
    So it should be fine to replace :

       long n=sc.nextLong();// n can be upto 10^9;
    

    by

       int n=sc.nextInt();// n can be upto 10^9;
    

提交回复
热议问题