Select four examples that initialize a NumberFormat reference using a factory.

Select four examples that initialize a NumberFormat reference using a factory.

Select four examples that initialize a NumberFormat reference using a factory.

A.
NumberFormat nf1 = new DecimalFormat();

B.
NumberFormat nf2 = new DecimalFormat(“0.00”) ;

C.
NumberFormat nf3 = NumberFormat.getInstance();

D.
NumberFormat nf4 = NumberFormat.getIntegerInstance();

E.
NumberFormat nf5 = DecimalFormat.getNumberInstance ();

F.
NumberFormat nf6 = NumberFormat.getCurrencyInstance () ;

Explanation:

getInstance
public static finalNumberFormatgetInstance()
Returns the default number format for the current default locale. The default format is one of the
styles
provided by the other factory methods: getNumberInstance(E), getIntegerInstance(D),

getCurrencyInstance(F)
or getPercentInstance. Exactly which one is locale dependant.
C: To obtain a NumberFormat for a specific locale, including the default locale, call one of
NumberFormat’sfactory methods, such as getInstance().
E:To obtain standard formats for a given locale, use the factory methods on NumberFormat such
asgetNumberInstance. These factories will return the most appropriate sub-class of
NumberFormat for a givenlocale.
F:To obtain standard formats for a given locale, use the factory methods on NumberFormat such
asgetInstance or getCurrencyInstance.
Reference:java.textClass NumberFormat



Leave a Reply 1

Your email address will not be published. Required fields are marked *