Java OCA OCP Practice Question 135

Question

How do you generate a string representing the value of a float f in a format appropriate for a locale loc?

A.  NumberFormat nf = NumberFormat.getInstance(loc); 
    String s = nf.format(f); //from w w  w . ja v a2s .c  o m

B.  NumberFormat nf = new NumberFormat(loc); 
    String s = nf.format(f); 

C.  NumberFormat nf = NumberFormat.getInstance(); 
    String s = nf.format(f, loc); 

D.  NumberFormat nf = new NumberFormat(loc); 
    String s = nf.format(f, loc); 


A.

Note

NumberFormat instances should be obtained by calling the static getInstance() method, not by calling a constructor.

To format a number, pass the number (and no other arguments) into the NumberFormat's format() method.




PreviousNext

Related