You are viewing a single comment's thread. Return to all comments →
you can also use \n instead of %n for printing a newline. Thanks for your help.
It's important to note that the '\n' newline character also adds a linefeed at the end. If you do not want the linefeed you should use "%n".
--The Java Tutorial: Formatting
what is line feed ?
line feed mean.
to add a new line
In Java, \r is always carriage return, and \n is line feed.
Why \n and %n both works for this program ?
Can you give an example which helps to understand the difference between them ?
%n is portable between various platforms, the value emmitted from %n will suits underlaying platform, where as value emmitted by \n is same for all the paltforms.
yeah, i've used \n instead of %n and both work fine. Thanks.
how about \t ??
\t is for vertical spacing
\t is tab
\t is horizontal tab that is equivalent to 4 spaces at a go
i think tab gives only 3 spaces
tab is a tab. It could be presented as 3, 4 or more spaces. Depends on the text editor, browser, etc. But most cases it's 4 spaces
This is what official documentation saids:
A new line character appropriate to the platform running the application. You should always use %n, rather than \n.