Java OCA OCP Practice Question 1868

Question

What is the result of the following?

public class Main { 
   public static void main(String[] args) { 
      LocalDateTime pi = LocalDateTime.of(2017, 3, 14, 1, 59); 
      DateTimeFormatter formatter = DateTimeFormatter 
         .ofPattern("M.ddhhmm"); 
      System.out.println(formatter.format(pi)); 
   } 
} 
  • A. 3.140159
  • B. 59.140103
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


A.

Note

While it is traditional to include the year when outputting a date, it is not required.

This code correctly prints the month followed by a decimal point.

After the decimal point, it prints the day of the month followed by the hours and minutes.




PreviousNext

Related