Java - What is the output: format NaN or Infinity?

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    System.out.printf("%.2e %n", Double.NaN);
    System.out.printf("%.2f %n", Double.POSITIVE_INFINITY);
    System.out.printf("%.2g %n", Double.NEGATIVE_INFINITY);
    System.out.printf("%(f %n", Double.POSITIVE_INFINITY);
    System.out.printf("%(f %n", Double.NEGATIVE_INFINITY);
  }
}


Click to view the answer

NaN 
Infinity 
-Infinity 
Infinity 
(Infinity)

Note

If the argument value for a floating-point conversion is NaN or Infinity, the output contains the strings "NaN" and "Infinity", respectively.

Related Quiz