public class Ques02 {
public static void main(
String[] args) {
int anInt = 100;
double aDouble = 100.00;
System.console().format("%2d - %1f", anInt, aDouble);
}
}
A. The program will output 100.000000 - 100.
B. The program will output 100 - 100.000000.
C. The program will throw a IllegalFormatConversionException at run-time.
D. The program will output 100 - 100.
Correct answer: B
Here the ordering of the arguments (anInt and aDouble) matters, not the formatting strings %2 - %1d. So the first output will be the value of anInt variable followed by a hyphen (-) followed by the value of aDouble variable.
Why?
Well, I know that "%2d - %1f" != "%2$d - %1$f" (in this case the output would be "100.000000 - 100"), but what does "%2d - %1f" mean?..
While writing this post I got an idea that "%2d - %1f" could mean minimum length.. Is it so?.. Or I'm on the wrong way?..
Thanks a lot!