Welcome Guest | Sign in | Register
Exceptions - Discussion Page For Q.2671 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Exceptions > Questions and Answers

Q: 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) {
System.out.println(stringConvert("0.3"));
System.out.println(stringConvert("0.3A"));
System.out.println(stringConvert(null));
}

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 {
System.out.println("Finally");
}
return false;
}

}
Find the output of the following code ?
A. true Finally B. true Exception in number formatting 0.3A Finally 
C. true Finally False D. Prints : "Finally" and give error message.

Answer and Explanation

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

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

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.