Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向数组中添加无穷大值_Java_Arrays_Infinity - Fatal编程技术网

Java 向数组中添加无穷大值

Java 向数组中添加无穷大值,java,arrays,infinity,Java,Arrays,Infinity,我想给数组的最后一个索引添加一个无穷大的值。我在java代码中尝试了类似的东西。我的数组是整数类型 Integer myInf = Integer.MAX_VALUE; array_name[length_of_array]=myInf; 它不起作用。我的代码中可能有什么问题?是否将数组的长度设置为正确的值?此外,数组是0索引的,因此最后一个索引比数组的大小小1 请尝试以下方法: array_name[array_name.length - 1] = Integer.MAX_VALUE; 数

我想给数组的最后一个索引添加一个无穷大的值。我在java代码中尝试了类似的东西。我的数组是整数类型

Integer myInf = Integer.MAX_VALUE;
array_name[length_of_array]=myInf;

它不起作用。我的代码中可能有什么问题?

是否将数组的
长度设置为正确的值?此外,数组是0索引的,因此最后一个索引比数组的大小小1

请尝试以下方法:

array_name[array_name.length - 1] = Integer.MAX_VALUE;

数组的
length\u是否设置为正确的值?此外,数组是0索引的,因此最后一个索引比数组的大小小1

请尝试以下方法:

array_name[array_name.length - 1] = Integer.MAX_VALUE;

在数组_名称中少使用一个索引值

Integer myInf = Integer.MAX_VALUE;
array_name[length_of_array - 1]=myInf;

在数组_名称中少使用一个索引值

Integer myInf = Integer.MAX_VALUE;
array_name[length_of_array - 1]=myInf;

你说不工作是什么意思?它说ArrayIndexOutOfBoundsException
Integer。MAX_VALUE
不是一个无穷大的值。你说不工作是什么意思?它说ArrayIndexOutOfBoundsException
Integer。MAX_VALUE
不是一个无穷大的值