Oracle Certified Professional Java Se 11 Developer · Free Practice Question Easy

Question 93

Question ID: UKOCP45559


Given code:


What is the result?

  • A Runtime Exception
  • B 01nd day of 2023
  • C 02nd day of 2023
  • D 32nd day of 2023
Reveal correct answer

Correct answer: D

Explanation

UKOCP45559:

Variable 'date' infers to LocalDate type and variable 'formatter' infers to DateTimeFormatter type.


In the format string, anything between opening and closing quote [''] is displayed as it is.


DD -> is for representing single digit number as 2 digits (4 as 04).

'nd day of' -> nd day of is displayed.

uuuu -> 4 digit representation for the year.


Output is: 32nd day of 2023.


NOTE: To display single quote, escape it with one more single quote. For example,

DateTimeFormatter.ofPattern("'It''s' DD'nd day of' uuuu"); this will help to print: [It's 32nd day of 2018] where as DateTimeFormatter.ofPattern("'It's' DD'nd day of' uuuu"); causes runtime exception.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need