Code: Select all
System.out.printf(" \" $%.2f \" ", -23.20); // software's answer
System.out.printf(" \" $%+.2f \" ", -23.20); // my answer
Moderator: admin
Code: Select all
System.out.printf(" \" $%.2f \" ", -23.20); // software's answer
System.out.printf(" \" $%+.2f \" ", -23.20); // my answer
Did you try it out? What does it print?Wisevolk wrote:Am I wrong if I say that "$%+.2f" would create an output of "$+23.20" ?
But you need to know it for the exam.jeremy_dd wrote:the '(' flag is also not very common, and not listed in the 'official' book....
but, i reckon, negative sign (-) will always be included in the result if it is in the input (unless we use "(" flag), so, basically, the flag "+" indicates if we only include positive sign (+).b. "+" Include a sign (+ or -) with this argument - Applicable only if conversion char is d or f (i.e. for numbers).
Code: Select all
double num = -3.4;
System.out.printf("\"%+.1f\"", num);
System.out.println();
System.out.printf("\"%.1f\"", num);
Code: Select all
double num = 3.4;
System.out.printf("\"%+.1f\"", num);
System.out.println();
System.out.printf("\"%.1f\"", num);
because i cannot think of any example of using "+" flag to include negative sign in the resulting string, negative sign will be there anyway if it is contained in the input.b. "+" Include the + sign with this argument if it is positive - Applicable only if conversion char is d or f (i.e. for numbers).
Users browsing this forum: No registered users and 20 guests