0
What's the difference between System.out.println and System.out.printf in java??
3 odpowiedzi
+ 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
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
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.