+ 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?
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();
+ 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
+ 1
one more question how do i get this to print a decimal?