Page 1 of 1

About Question enthuware.ocpjp.v11.2.3658 :

Posted: Wed Apr 14, 2021 10:52 am
by maria_maria

Code: Select all

public static float parseFloat1(String s1) {
        try {
            return Float.parseFloat(s1);
        } catch (NumberFormatException e) {
            return 0.0f;
        } catch (IllegalArgumentException e) {
            return Float.NaN;
        }
    }
The correct answer is Calling parseFloat1("junk"); will return 0.0f. but I think it should be Calling parseFloat1("junk"); will return 0.0.
Indeed, there is a difference between returning(a float 0.0f) and actually printing(a float 0.0).
I am interested in your take on this matter.

Re: About Question enthuware.ocpjp.v11.2.3658 :

Posted: Wed Apr 14, 2021 11:56 pm
by admin
0.0 is a double value. Why would it return 0.0 when the return type of the method is float?
Also, the return statement says return 0.0f;