Share on Google+Share on Google+

SCJP Module-6 Question-1

The program given below will test your understanding of Float primitive data types and functions in Java program.

Given below the sample code :

public class SuperClass {
public static void main(String[] args) {


public static boolean stringConvert(String s) {

float factor = 0;
try {
factor = Float.valueOf(s).floatValue();
return true;
} catch (NumberFormatException e) {
System.out.println("Exception in number formatting " + s);
factor = Float.NaN;
} finally {
return false;


Find the output of the following code ?

1. true   Finally

2.  true   Exception in number formatting 0.3A  Finally

3. true Finally False

4. Prints : "Finally"  and give error message.

Answer :


Explanation :

Because the number "0.3A" is not a valid number and also error in converting null to string.



Posted on: July 12, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.