About Question enthuware.ocpjp.v11.2.3658 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

About Question enthuware.ocpjp.v11.2.3658 :

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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;
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests