Java: how do I initialize an array size if it's unknown?

前端 未结 7 772
庸人自扰
庸人自扰 2021-02-04 03:47

I\'m asking the user to enter some numbers between 1 and 100 and assign them into an array. The array size is not initialized since it is dependent on the number of times the us

7条回答
  •  没有蜡笔的小新
    2021-02-04 03:57

    **input of list of number for array from single line.

       String input = sc.nextLine();
        String arr[] = input.split(" ");
        int new_arr[] = new int[arr.length];
        for(int i=0; i

提交回复
热议问题