Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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_Algorithm_Permutation - Fatal编程技术网

Java 打印数组元素的所有可能排列

Java 打印数组元素的所有可能排列,java,arrays,algorithm,permutation,Java,Arrays,Algorithm,Permutation,我正在编写一个程序,我试图找到一种方法,在Java中找到数组元素的所有可能排列,但没有成功 我的代码是: 公共类置换{ 公共静态void main(字符串[]args){ int[]列表=新int[3]; System.out.println(“输入数组元素”); 扫描仪sc=新的扫描仪(System.in); for(int i=0;i

我正在编写一个程序,我试图找到一种方法,在Java中找到数组元素的所有可能排列,但没有成功

我的代码是:

公共类置换{
公共静态void main(字符串[]args){
int[]列表=新int[3];
System.out.println(“输入数组元素”);
扫描仪sc=新的扫描仪(System.in);
for(int i=0;i
此代码持续运行并引发错误:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
    at Permutation.swap(Permutation.java:34)
    at Permutation.permutation(Permutation.java:27)
    at Permutation.permutation(Permutation.java:28)
    at Permutation.main(Permutation.java:15)
我无法理解在这个程序中要做什么,这样它才能产生所需的输出


程序抛出的这个错误是什么意思???

您之所以会出现这个错误,是因为您正在尝试访问项目,而不是在数组中尝试更改


第25行的i=0

这是否回答了您的问题?ArrayIndexOutOfBoundsException就是这个意思。在某个地方,您对数组使用的索引号大于该数组的最大索引或小于该数组的最小(不太可能)索引。具体来说,是“某处”或第34行。