What will be the output of the program?
public class Example51
{
void run()
{
String out = String.format("%05.2f", 3.14159);
System.out.println(out + " " + out.length());
}
public static void main(String[] args)
{
new Example51().run();
}
}
Answer: C
The format asks for a fixed-point number two places after the decimal point, in a field five characters wide, zero padded. That gives 03.14, which is five characters including the point. Without the 0 flag the padding would have been spaces.
Please log in or register to report this question.