The output of this statement comes out to be 7.00settrue
I do not understand what the initial 02 (just before the decimal point) means. API says that if 0 is present as the flag, the argument will be padded by zeroes.Based on this, I thought the output would be 07.00settrue, but it is not.
On the other hand, if I have the format string as System.out.printf("%02d%s%b",new Integer(7),new StringBuffer("set"),"fAlSE"); the output is 07settrue where the padded zeroes come into effect.
The same thing is not happening for float type. Why?
I think you are not getting any padding as there is no extra space to use padding. In you example
%02d you have to print 7 and you have two characters to print it. So there is one padded 0.
But in the question %02.2f, you have to represent 7 in min two characters and there must be a fractional part of 2 digits. So the text will be displayed in three characters i.e. 7.00 so there is no place for extra padding.
I am not sure about this so let's see what others have to say...