ran*_*jun 2 java arrays long-integer
我希望输入一个int和另一个longex:1和1000000000,现在我希望创建一个大小为1000000000的数组.然后在数组的每个索引处,存储int val,ex : arr[100000000] = 4.
当我试图这样做时,Netbeans在这一行显示错误:
arr = new long[y+1]` and `arr[j] = 0`
Run Code Online (Sandbox Code Playgroud)
"从long到int可能有损转换".这是我的代码: -
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;
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*Mmm 10
数组索引是Java中的一个整数,编译器会给你建议.因此,最大阵列大小(近似)Integer.MAX_VALUE.对于更大的数组,您应该使用ArrayList.
绕过这污垢快速
arr = new long[(int)y+1];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23424 次 |
| 最近记录: |