0

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] + ""); 
        }

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.