Given the code fragment:
You want to display the value of currency as $100.00.
Which code inserted on line 1 will accomplish this?
Given the code fragment:
You want to display the value of currency as $100.00.
Which code inserted on line 1 will accomplish this?
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);
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
the answer is D
D is correct
D is right
D is the correct, as A returned the currency set for the number format.
D is the correct answer
D is the correct answer
https://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html#getCurrencyInstance(java.util.Locale) D
Right answer is option D