Menu
Question Index
...

What will be the output of the following program?

public class PrintStatement4
{
    public static void main(String args[])
    {
        System.out.print(formatDouble(0.0000000123456789) + " ");
        System.out.print(formatDouble(1234567890000000.0) + " ");
        System.out.print(formatDouble(0.0000000123456789012345678) + " ");
        System.out.print(formatDouble(1234567890123456780000000.0));
    }
    public static String formatDouble(double x)
    {
        return String.format("%.17g", x).replaceFirst("\\.?0+(e|$)", "$1");
    }
}


1.23456789e-08 1.2345678901234567e-08 1234567890000000 1.2345678901234568e+24
1.2345678901234568e+24 1234567890000000 1.2345678901234567e-08 1.23456789e-08
1.23456789e-08 1234567890000000 1.2345678901234567e-08 1.2345678901234568e+24
1.2345678901234568e+24 1.2345678901234567e-08 1234567890000000 1.23456789e-08
Compilation Error or Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App