Java OCA OCP Practice Question 2150

Question

What is the result of the following?.

public class PiDay { 
   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.011459
  • B. 3.140159
  • C. 59.011459
  • D. 59.140103
  • E. The code does not compile.
  • F. The code compiles but throws an exception at runtime.


D.

Note

While this code misuses formatting characters, it does compile and run successfully, making Options E and F incorrect.

A lowercase m represents the minutes, which are 59 in this case, ruling out Options A and B.

The rest of the code prints the date, hour, and month.

This gives the value 59.140103, making Option D the answer.




PreviousNext

Related