About Question enthuware.ocpjp.v7.2.1409 :

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

Moderator: admin

Post Reply
renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

About Question enthuware.ocpjp.v7.2.1409 :

Post by renatumb »

Code: Select all

System.out.printf(" \" $%.2f \" ", -23.20); // software's answer
System.out.printf(" \" $%+.2f \"  ", -23.20);  // my answer
Both will generate the same output but it considered my answer wrong

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

You are right. This is difficult to check. I have added this as a correct answer as well but there could be more :(
-Paul.
If you like our products and services, please help us by posting your review here.

Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by Wisevolk »

The corrected answer is always "$%.2f", so from my opinion the you should correct either the answer "$23.20" or the statement "$%+.2f"

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

Since it cannot show all the possibilities, it just shows one of the two. But if you enter any of the correct options i.e. $%+.2f; or $%.2f;, it will be marked as correct.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by Wisevolk »

Am I wrong if I say that "$%+.2f" would create an output of "$+23.20" ?

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

Wisevolk wrote:Am I wrong if I say that "$%+.2f" would create an output of "$+23.20" ?
Did you try it out? What does it print?
-Paul.
If you like our products and services, please help us by posting your review here.

Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by Wisevolk »

Ok you're write I had a bug vision, may be I could take some rest !! I saw a + in the answer instead of a minus !!

DesRenthuware
Posts: 32
Joined: Wed Aug 28, 2013 6:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by DesRenthuware »

Hi.

I think this question has evolved. When checking the answers (via "Show correct answer"), a message pops up saying there are multiple answers, but only one is being shown. I assume this is because the original question asked people to input the formatting string to obtain the answer as opposed to predicting the output generated? This is no longer the case.

Cheers

jeremy_dd
Posts: 9
Joined: Mon Nov 11, 2013 3:11 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by jeremy_dd »

the '(' flag is also not very common, and not listed in the 'official' book....

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

jeremy_dd wrote:the '(' flag is also not very common, and not listed in the 'official' book....
But you need to know it for the exam.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

monseigneur
Posts: 6
Joined: Sun Aug 09, 2015 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by monseigneur »

hi mate,

could you please clarify the following:
in flags we have:
b. "+" Include a sign (+ or -) with this argument - Applicable only if conversion char is d or f (i.e. for numbers).
but, i reckon, negative sign (-) will always be included in the result if it is in the input (unless we use "(" flag), so, basically, the flag "+" indicates if we only include positive sign (+).

is this correct?

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

No, + sign means you want to include both the signs i.e. + and - in the resulting string. See this table: https://docs.oracle.com/javase/tutorial ... ormat.html
You may also want to try it out and see what happens.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

monseigneur
Posts: 6
Joined: Sun Aug 09, 2015 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by monseigneur »

thank you, that is clear,

could you give a short example of negative sign not being included in the resulting string unless we use "+" flag, though?
i mean, let's say we have

Code: Select all

double num = -3.4;
System.out.printf("\"%+.1f\"", num);
System.out.println();
System.out.printf("\"%.1f\"", num);
the result is absolutely the same, innit? "-3.4"

and if we have

Code: Select all

double num = 3.4;
System.out.printf("\"%+.1f\"", num);
System.out.println();
System.out.printf("\"%.1f\"", num);
we will have "+3.4" and "3.4"

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

I don't know if you can do that. You will need to check the table mentioned above and see how to avoid printing the - sign.
If you like our products and services, please help us by posting your review here.

monseigneur
Posts: 6
Joined: Sun Aug 09, 2015 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by monseigneur »

alright, man, thanks for your time.

i don't have troubles hiding negative sign, i just feel that correct definition of the flag would be
b. "+" Include the + sign with this argument if it is positive - Applicable only if conversion char is d or f (i.e. for numbers).
because i cannot think of any example of using "+" flag to include negative sign in the resulting string, negative sign will be there anyway if it is contained in the input.
unless we use "(" flag, of course.
and if we use "(" flag, having "+" flag as well will not change anything, we will still have no negative sign in the resulting string.

but we can leave it here, doesn't really matter.

great job on the software and the site, mate, real helpful!

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

Re: About Question enthuware.ocpjp.v7.2.1409 :

Post by admin »

OK, I understand what you mean. You will need to take this up with Oracle though because as per their table, "+ Includes sign, whether positive or negative." :)
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