Menu
Question Index
...

What will be the output of the following program?

public class PrintStatment2
{
    public static void main(String args[])
    {
        System.out.print(formatDouble(-0.0) + " ");
        System.out.print(formatDouble(0.0) + " ");
        System.out.print(formatDouble(1.0) + " ");
        System.out.print(formatDouble(1.2) + " ");
    }
    public static String formatDouble(double x)
    {
        return String.format("%.17g", x).replaceFirst("\\.?0+(e|$)", "$1");
    }
}


-0.0 0.0 1.0 1.2
-0 0 1 1.2
-0 0 1.0 1.2
-0 0 1 1
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