Array Printing Java

后端 未结 3 1535
面向向阳花
面向向阳花 2021-01-28 12:05

Basically I want my code to enable the user to enter x amount of integers (they chose x), then they will then store each of their inputted integer values in my array.

Fo

3条回答
  •  -上瘾入骨i
    2021-01-28 12:18

    You can also use java.util.ArrayList

    ArrayList myArray = new ArrayList(amount);
    
    for (int counter = 0; counter < amount; counter ++){
     myArray.add(counter,input.nextInt());
    }
    System.out.println(myArray);
    

    prints array like this -> [1, 2, 3, 4]

提交回复
热议问题