[英]Adding infinity value to an array
I want to add an infinity value to the last index of an array. 我想向数组的最后一个索引添加一个无穷大值。 I tried something like this in my java code.
我在Java代码中尝试了类似的方法。 My array is an integer type.
我的数组是整数类型。
Integer myInf = Integer.MAX_VALUE;
array_name[length_of_array]=myInf;
It is not working. 它不起作用。 What might be the problem in my code?
我的代码可能是什么问题?
Use one less index value in array_name. 在array_name中使用少一个的索引值。
Integer myInf = Integer.MAX_VALUE;
array_name[length_of_array - 1]=myInf;
Is length_of_array
set to the correct value? length_of_array
是否设置为正确的值? Also, arrays are 0-indexed, so the last index is 1 less than the size of the array. 此外,数组的索引为0,因此最后一个索引比数组的大小小1。
Try this instead: 尝试以下方法:
array_name[array_name.length - 1] = Integer.MAX_VALUE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.