Java OCA OCP Practice Question 2586

Question

Consider the following program:

import java.util.*;

class Main {//from  w w w. j  ava  2s .  c om
        public static void main(String []args) {
                Formatter formatter = new Formatter();
                Calendar calendar = Calendar.getInstance(Locale.US);
                calendar.set(/* year =*/ 2012,
                        /* month = */ Calendar.FEBRUARY, /* date = */ 1);
                formatter.format("%tY/%tm/%td",
                        calendar, calendar, calendar);
                System.out.println(formatter);
        }
}

Which one of the following options is correct?

  • a) The program throws a MissingFormatArgumentException.
  • b) The program throws an UnknownFormatConversionException.
  • c) The program prints the following: 2012/02/01.
  • d) The program prints the following: 12/Feb/01.


c)

Note

The format specifier %t allows for formatting date and time information.

It takes as suffix the format and part of the date or time information.

The format Y is for the year displayed in four digits.

The format m is for month as decimal (with months in the range 01 to 12).

The format d is for the day of month as decimal (with the days in the range 01 - 31).




PreviousNext

Related