How to return a specific element of an array?

前端 未结 4 1835
臣服心动
臣服心动 2020-12-20 01:49

I want to return odd numbers of an array yet Eclipse doesn\'t seem to accept my return array[i]; code. I think it requires returning a whole array since I set a

4条回答
  •  忘掉有多难
    2020-12-20 02:38

    You code should look like this:

    public int getElement(int[] arrayOfInts, int index) {
        return arrayOfInts[index];
    }
    

    Main points here are method return type, it should match with array elements type and if you are working from main() - this method must be static also.

提交回复
热议问题