无法将int []数组转换为int []

时间:2015-12-05 20:59:55

标签: java arrays vector int

我继续得到错误,我在第27行作为参数传递的数组不能转换为int [],尽管我已经声明了它。谁能解释一下为什么会这样? Compiler Message

import java.util.*;

class C10E3
{
    static Scanner console = new Scanner(System.in);
    public static void main(String[] args)
    {
        //declaration phase
        int[] array ={4, 23, 65, 34, 82, 37, 12, 17, 24, 36, 82, 51};
        int[] arrayUpdated = new int[11];
        int intToBeRemoved;
        int intCounter;
        Remover remove = new Remover();

        System.out.println("Which of these elements shalls be removed from thr array?");
        //display array
        for (intCounter = 0; intCounter < 12; intCounter++)
            System.out.print(array[intCounter]);
        System.out.print("\n");
        //determine int to be removed
        intToBeRemoved = console.nextInt();
        //call method remove to remove int
        arrayUpdated = remove.removeItem(array, 12, intToBeRemoved);
        System.out.print("Updated Array: ");
        for (intCounter = 0; intCounter < 11; intCounter++)
            System.out.print(array[intCounter]);
    }
}

class Remover
{
    private Vector vector = new Vector();

    public void removeItem(int[] array, int intArrayLength, int intToRemove)
    {
        boolean boolIsRemoved;
        int intCounter;

        for (intCounter = 0; intCounter < intArrayLength; intCounter++)
            vector.addElement(array[intCounter]);

        boolIsRemoved = vector.removeElement(intToRemove);
        if (boolIsRemoved == true)
            {
                vector.toString();
            }
            else
            {
                System.out.println("Element not present in array.");
            }
    }
}

2 个答案:

答案 0 :(得分:1)

String[] names = {"John","Tim","Sam","Ben"}; myFirebaseRef.setValue(names);

arrayUpdated = remove.removeItem(array, 12, intToBeRemoved);

public void removeItem(int[] array, int intArrayLength, int intToRemove)的返回类型无效,您无法将其分配给removeItem()

答案 1 :(得分:1)

你的错误来自这一行:

In [38]: optimize.fmin(fn2, x0=np.array([0,0]))
Optimization terminated successfully.
         Current function value: 2.227274
         Iterations: 64
         Function evaluations: 121
Out[38]: array([ 0.29782369,  0.62167083])

您的arrayUpdated = remove.removeItem(array, 12, intToBeRemoved); 方法返回void,并且您正尝试将其分配给变量。