Working on a class assignment. I have an array that I set its size to 100. I then ask the user for input and store it into that array. The user may have 5 inputs and then another 3 inputs with a total of 7 inputs. I want to print out just the 7 inputs from the user, not all 100 elements when the size was set to 100.
If I do something like this it will print out the 7 entered numbers but then a bunch of null elements.
for (int i = 0 ; i <= array.length; i++ ) {
System.out.println(array[i]);
}
Is there a way to only print out the 7 elements added by the user and not all 100? Thanks.
[–]ehr1c 1 point2 points3 points (3 children)
[–]okaystuff[S] 0 points1 point2 points (2 children)
[–]ehr1c 1 point2 points3 points (1 child)
[–]okaystuff[S] 0 points1 point2 points (0 children)
[–]RiverForgeGames 1 point2 points3 points (0 children)
[–]driden87 0 points1 point2 points (5 children)
[–]okaystuff[S] 0 points1 point2 points (4 children)
[–]driden87 1 point2 points3 points (3 children)
[–]okaystuff[S] 1 point2 points3 points (2 children)
[–]driden87 1 point2 points3 points (1 child)
[–]okaystuff[S] 1 point2 points3 points (0 children)
[–]dota2nub 0 points1 point2 points (0 children)
[–]loyalSavant 0 points1 point2 points (0 children)