SCJP題庫第159題
Given:
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here
Which code, inserted at line 14, sets the value of b to 314.159,26?
A. b = nf.parse(input);
B. b = nf.format(input);
C. b = nf.equals(input);
D. b = nf.parseObject(input);
Ans: B
解說:
14行插入那一行設定了b物件的值為314.159,26
parse(剖析)的語意一般是從字串轉成所要的類別型態物件,如Integer.parseInt
NumberFormat中的format方法是將數值以所指定的格式輸出,回傳值型態是String
Comments