0

What's the difference between System.out.println and System.out.printf in java??

31st May 2019, 12:57 PM
Nino{}Neon
3 Answers
+ 4
printf function doesn't create a new line after printing on screen... While println function creates a new line after printing the string inside argument. for example: System.out.printf("hi"); System.out.printf("hello"); System.out.println("okay"); System.out.println("oooh"); Output : hihellookay oooh
31st May 2019, 1:13 PM
Raj Chhatrala
Raj Chhatrala - avatar
0
System.out.println prints the statement and moves to the next line System.out.printf and System.out.print print the statement and remains in the same line
2nd Jun 2019, 3:00 AM
PRAVEEN R
PRAVEEN R - avatar
0
println function creates a new line. printf function creates or doesn't create a new line. Moreover, you can give a format to any data types. For example: double a = 12.3347; System.out.printf("%.2f\n", a); Output: 12.33 \n <-- creates a new line.
3rd Jun 2019, 7:49 PM
Junior Oblitas
Junior Oblitas - avatar