public class MainClass {
public static void main(String[] argv) {
System.out.println(stringConvert("0.2"));
System.out.println(stringConvert("0.2A"));
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("Bad number " + s);
factor = Float.NaN;
} finally {
System.out.println("Finally");
}
return false;
}
}
|