Adding integers to an int array

前端 未结 7 867
我在风中等你
我在风中等你 2021-02-05 01:57

I am trying to add integers into an int array, but Eclipse says:

cannot invoke add(int) on the array type int[]

Which is completely

7条回答
  •  暖寄归人
    2021-02-05 02:17

    An array doesn't have an add method. You assign a value to an element of the array with num[i]=value;.

    public static void main(String[] args) {
        int[] num = new int[args.length];
        for (int i=0; i < num.length; i++){
          int neki = Integer.parseInt(args[i]);
          num[i]=neki;
        }
    }
    

提交回复
热议问题