+ 1

I dont understand

i dont really understand printf can someone explain? so i tried an example with printf and it was badically enter 2 multiples and it prints it out and the last line was System.out.printf("The product of both numbers is %d", sum); can't you do the same with just println and a (+ sum)? what advantage does printf have?

17th Feb 2017, 4:08 PM
flamethekid
flamethekid - avatar
3 odpowiedzi
+ 1
With this statement you can get the output as per your requirement. Example: double y= 7.86547, x= 5.6437637, sum; sum = x+y; System.out.printf("%.2f",sum); Will give you an output 13.51 by rounding off the remaining decimal values. One more similar statement is System.out.format();
17th Feb 2017, 6:22 PM
Kommoju Sunil Kumar
Kommoju Sunil Kumar - avatar
+ 1
ok few more questions sorry so system.out.format will do the exact same thing as printf? and I'm still a bit confused on the advantages of printf to println
17th Feb 2017, 11:05 PM
flamethekid
flamethekid - avatar
+ 1
one more question how do i get this to print a decimal?
17th Feb 2017, 11:12 PM
flamethekid
flamethekid - avatar