Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 6

Given the code fragment:

You want to display the value of currency as $100.00.

Which code inserted on line 1 will accomplish this?

    Correct Answer: D

    To format a number as currency in a specific locale, the appropriate method to use is getCurrencyInstance(Locale). This method returns a currency formatter for any specified locale, which can then be used to format the number as currency. The correct code to put on line 1 is: NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);

Discussion
james2033Option: D

import java.text.NumberFormat; import java.util.Locale; public class Bar { public static void main(String[] args) { Locale locale = Locale.US; // Line 1. NumberFormat formatter = NumberFormat.getInstance(locale); // D. double currency = 1_00.00; System.out.println(formatter.format(currency)); } } // Result: // 100

LebanninOption: D

the answer is D

StavokOption: D

D is correct

Mukes877Option: D

D is right

iCOWOption: D

D is the correct, as A returned the currency set for the number format.

bharathdaveOption: D

D is the correct answer

Ankit1010Option: D

D is the correct answer

alex_konOption: D

https://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html#getCurrencyInstance(java.util.Locale) D

Leksh_geethOption: D

Right answer is option D