Home Tutorial Java Scjp Part12 SCJP Module-12 Question-8

 
 

Share on Google+Share on Google+
SCJP Module-12 Question-8
Posted on: July 22, 2010 at 12:00 AM
Advertisement
The given sample program will test your understanding about parsing the primitive data types to some other format.

Given below the sample code :

0. public class testparse {
1. public static void format(String str) {
2. try {
3. float flt = Float.parseFloat(str);
4. } catch (NumberFormatException nfe) {
5. flt = 0;
6. } finally {
7. System.out.println(flt);
8. }
9. }
10.public static void main(String[] args) {
11.format("illlegal");
12.}}

How can we correct the above code?

1. no need of correction

2. By adding "static float flt = 0;" before line 1

3. By adding "static float flt = 0;" inside try block.

4. By defining "flt" in every block .

Answer

(2)

Advertisement

Related Tags for SCJP Module-12 Question-8:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com