Java 我的运动冻结了,我不';我不明白为什么

Java 我的运动冻结了,我不';我不明白为什么,java,arrays,vector,netbeans,duplicates,Java,Arrays,Vector,Netbeans,Duplicates,我创建了这个问题,程序在其中查找重复的数字。因为它不起作用 package javaapplication5; /** * * @author miste */ public class JavaApplication5 { /** * @param args the command line arguments */ public static void main(String[] args) { NewClass n = new

我创建了这个问题,程序在其中查找重复的数字。因为它不起作用

package javaapplication5;

/**
 *
 * @author miste
 */
public class JavaApplication5 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        NewClass n = new NewClass();
        int[] numero = {2, 3, 4, 5, 6, 3};
        n.cerca(numero);
    }

}

PackageJavaApplication5;
导入静态java.lang.reflect.Array.get;
/**
*
*@作者米斯特
*/
公共类新类{
int[]numero={2,3,4,5,6,3};
公共无效cerca(整数[]数字){
int-tmp=0;
对于(int i=0;i<7;i++){
tmp=数字[i];
}
对于(int j=0;j<7;j++){
如果(数字[j]==tmp){
System.out.println(“il replicoè”+tmp);
}
}
}
}

您的数组长度为6。您可以迭代到的最大索引是5。由于您正在从0迭代到6,因此它将为您提供ArrayIndexOutOfBoundsExcption。
您可以通过将循环条件更改为
来纠正它,因为应用程序不会冻结,而是会冻结。如果此问题得到解决,程序将停止运行。
package javaapplication5;

import static java.lang.reflect.Array.get;

/**
 *
 * @author miste
 */
public class NewClass {
    int [] numero = {2, 3, 4, 5, 6, 3};

    public void cerca(int[] numero) {
        int tmp = 0;
        for (int i = 0; i < 7; i++) {
            tmp = numero[i];
        }
        for (int j = 0; j < 7; j++) {
            if (numero[j] == tmp) {
                System.out.println("il duplicato è " + tmp);
            }
        }
    }
}