问题描述
我是Java的新手,我想在Java中使用较大的输入大小数组.但是给了我一些运行时错误-NZEC,我对此一无所知,我也对此错误进行了一些研究,但没有发现与我的问题有关的任何内容.
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 but did'nt find anything related to my problem.
long n=sc.nextLong();// n can be upto 10^9;
long a[]=new long[n];// declaring array of n;
我也遇到了编译时错误,即:
also i am facing a compile time error which is :
error: incompatible types: possible lossy conversion from long to int
任何人都可以解决我的这个问题吗?
can anyone please solve my this issue??
推荐答案
数组大小限制为int
大小(即约20亿).您正在尝试使用long
初始化一个.可以将尺寸读入int
或使用long a[]=new long[(int)n];
进行整形.
Array sizes are limited to int
size (i.e. about 2 billion). You're trying to initialize one with long
. Either read the size into an int
or cast the long with long a[]=new long[(int)n];
.
我建议前者避免任何细微的错误.
I recommend the former to avoid any subtle bugs.
这篇关于如何在Java中采用大尺寸数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!