Menu
Question Index
...

What will be the output of the following program?

import java.text.DecimalFormat;
public class FormatDoubles {
    public static void main(String[] args) {
        print(12.45);
        print(12312.45);
        print(2000.450223);
        print(3.4545454454);
    }
    public static void print(double value) {
        DecimalFormat f1 = new DecimalFormat("0000.00");
        DecimalFormat f2 = new DecimalFormat("0.0000");
        DecimalFormat f3 = new DecimalFormat("##00.00##");
        DecimalFormat f4 = new DecimalFormat("#####.#############");
        DecimalFormat f5 = new DecimalFormat("#.00");
        System.out.print(f1.format(value) + " ");
        System.out.print(f2.format(value) + " ");
        System.out.print(f3.format(value) + " ");
        System.out.print(f4.format(value) + " ");
        System.out.println(f5.format(value));
    }
}


12.45 12.4500 12.45 0012.45 12.45
12312.45 12312.4500 12312.45 12312.45 12312.45
2000.450223 2000.4502 2000.4502 2000.45 2000.45
3.4545454454 3.4545 03.4545 0003.45 3.45
0012.45 12.45 12.4500 0012.45 12.45
12312.45 12312.45 12312.4500 12312.45 12312.45
2000.45 2000.4502 2000.4502 2000.45 2000.45
0003.45 03.4545 3.4545 0003.45 3.45
0012.45 12.4500 12.45 12.45 12.45
12312.45 12312.4500 12312.45 12312.45 12312.45
2000.45 2000.4502 2000.4502 2000.450223 2000.45
0003.45 3.4545 03.4545 3.4545454454 3.45
None of the above

Doubts

Problems

Topic: Advanced Java Programming Concepts

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App