Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (3.5k points)
How do I get a platform-dependent newline in Java? I can’t use "\n" everywhere.

1 Answer

0 votes
by (46k points)

If you don't want to use the line separator property ("\n"), you can try string format and use %n (works for Java 1.5 or above)


Calendar c = ...;

String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY%n", c); \

String s2 = String.format; 

// %% becomes %    

// and `%n` becomes a newline 

Click here for more details.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

Browse Categories