Given:
3. import java.text.*; 4. public class Main { 5. public static void main(String[] args) { 6. String s = "987.123456"; 7. double d = 987.123456d; 8. NumberFormat nf = NumberFormat.getInstance(); 9. nf.setMaximumFractionDigits(5);//w ww. j ava2s .c om 10. System.out.println(nf.format(d) + " "); 11. try { 12. System.out.println(nf.parse(s)); 13. } catch (Exception e) { System.out.println("got exc"); } 14. } 15. }
Which are true?
Choose all that apply.
parse()
must be placed within a try/catch blockD, F, and G are correct.
The setMaximumFractionDigits()
applies to the formatting, but not the parsing.
The try/catch block is placed appropriately.
This one might scare you into thinking that you'll need to memorize more than you really do.
If you can remember that you're formatting the number and parsing the string, you should be fine for the exam.