2

What is the difference between %n and \n in Java?

For example,

System.out.printf("Hello, world! %n");

and

System.out.printf("Hello, world! \n");

Both return the same output for me.

S. Park
  • 41
  • 1
  • 3

1 Answers1

5

Well, as far as i know the difference is that %n will always output the correct line break depending on the platform while \n won't.

N.K
  • 1,601
  • 2
  • 19
  • 31