Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJacqueline Steremberg
2,376 PointsIs it really necessary to add a newline for each array element?
I lost a lot of time looking for my error and the problem was i declared all the elements on the same line. Is it really wrong?
2 Answers
Alessandro Calorì
10,241 PointsJava does not care about newlines. You could theorically write all of your code on a single line. The imporant thing is that the syntax of the code is correct.
int[] numbers = { 1, 2, 3, 4 };
have the same meaning of:
int[] numbers =
{
1,
2,
3,
4
};
Watch out for semicolumns and columns: those are ESSENTIAL.
Jacqueline Steremberg
2,376 PointsI thought so! Thank you very much for your replies!
Luke O'Neill
7,822 PointsLuke O'Neill
7,822 PointsYou were probably getting the error because of how treehouse checks your code. Alessandro hit the nail on the head though, you don't need new lines.