可能有损转换从long到int [英] Possible Lossy conversion from long to int
问题描述
我希望输入一个 int
和另一个 long
ex:1和1000000000,现在我想创建一个大小为1000000000的数组。然后在数组的每个索引处,存储int val,例如: arr [100000000] = 4
。
I wish to enter one int
and another long
ex: 1 and 1000000000, and now I wish to create an array of size 1000000000. And then at each index of array, store int val, ex: arr[100000000] = 4
.
当我尝试这样做时,Netbeans在这一行显示错误:
When I'm trying to do this Netbeans shows me an error in this line:
arr = new long[y+1]` and `arr[j] = 0`
从long到int的可能有损转换。
这是我的代码: -
"Possible Lossy conversion from long to int". Here's my code:-
public static void main(String[] args) throws IOException
{
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
String[] xe = s.readLine().split(" ");
int x = Integer.parseInt(xe[0]);
long y = Long.parseLong(xe[1]);
long []arr;
arr = new long[y+1];
for(long j=0;j<=y;j++)
arr[j] = 4;
}
推荐答案
数组索引是一个整数Java和编译器会建议你。因此,最大数组大小(近似地) Integer.MAX_VALUE
。对于更大的数组,你应该使用ArrayList。
Array index is an integer in Java and the compiler will advice you. So maximum array size is (aproximately) Integer.MAX_VALUE
. For bigger arrays you should use ArrayList.
绕过这个污垢&快速
To go around this dirt&quick
arr = new long[(int)y+1];
这篇关于可能有损转换从long到int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!