Array Printing Java

后端 未结 3 1579
面向向阳花
面向向阳花 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条回答
  •  死守一世寂寞
    2021-01-28 12:18

    Ok, you can take away the for loop and do it this way

    System.out.println(Arrays.toString(myArray));
    

    I would strongly recommend to do it with the for loop. It prints one element at the time every time the loop runs, and with your for loop it runs through every element. You need to change the println to this (inside you for loop)

    System.out.println(myArray[counter]);
    

    or if you want to have the array on the same line

    System.out.print(myArray[counter]+ " ");
    

    Later on when programming you are going to see how useful this is compared to Arrays.toString() method.

提交回复
热议问题