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 trial

Java

Hello I want to understand exactly what would coders use the "\n" function for?

Trying to understand this function and what it is used for?

1 Answer

\n is not a function, it is an escape sequence that creates a newline wherever the sequence is in the string, meaning anything after it will be on a separate line

console.printf("This is on one line \nthis is on another line");

would output

This is on one line
This is on another line

there are many times when you need to output something on a separate line, and thats when \n comes in handy.

there are many different escape sequences (such as \t which creates a tab)

you can read more about escape sequences here

Thanks Stone