Reputation: 19
To my understanding, this for loop is supposed to print out each element of my int array, incorrectans. Yet instead, when the length of incorrectans is set to 3, the output, instead of being the three expected integers inside my array, end up being a series of five numbers: 11012. Something is obviously wrong, but I'm pretty new to Java and can't figure out what I did wrong. I'm pretty sure that I could also somehow use java.util.Arrays to make this easier on myself, but I'm trying to gain an understanding of arrays without relying on the library first, apologies if the solution is 'obvious'.
for (int i = 0; i < incorrectans.length; i++) {
System.out.print(incorrectans[i] + "");
}
Upvotes: 0
Views: 42
Reputation: 393771
Add spaces between the elements :
for (int i = 0; i < incorrectans.length; i++) {
System.out.print(incorrectans[i] + " ");
}
""
is an empty String, not a space.
Upvotes: 6