For eg:- System.out.println(“Simple interest is” +si);
and why we could not use comma after double quote
Why we use + in the printing section
Please give the proper explanation
If you want to use comma you can use System.out.format(). It works almost like printf syntax. And the other part of your query, System.out.println() first builds the entire String object to be displayed. Then displays it on the console. That’s why we use + to concat the strings inside Sopln()
this is the syntax which is used in println()
if we want access any variable, then it should be outside the quote
Sorry Deepak, didn’t get you?
printf() provides string formatting similar to the printf function in C.
println() prints a new blank line and then msg.
printf() is primarily needed when you need to print big strings to avoid string concatenaion in println() which can be confusing at times. (Although both can be used in almost all cases).
int x = 1;int y = 2;
println("x: " + x + " y: " + y);
printf(“x: %d y: %d\n”, x, y);
using printf we can easily print any fractional no. upto the requied decimal point.
Eg. printf("%.3f",x); // prints x up to 3 decimal places.
hope this helps
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.