About Question com.enthuware.ets.scjp.v6.2.304 :

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

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.304 :

Post by ETS User »

Is there an error with this question?

The solution shows 'double or float' and the explanation gives 'int,long,float or double'

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

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Post by admin »

Yes, it is correct because it does not say only double or float.
If you like our products and services, please help us by posting your review here.

devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Post by devlam »

I was expecting that when giving the amount a type of float or double the real result would be given.
So 0,8. But it gives 1.0 as a result.
Only declaring rate as a float/double of casting the rate within the expression to float/double will give the real result.
I don't understand why this is.

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

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Post by admin »

If you have only int variables in a term, then integer operation is performed for that term. For example, in the term rate/100*1, all are ints. Therefore, it will actually return 0. If you do ((double)rate)/100*1, now you have a double in the term, so everything in that term will be promoted to a double and it will return .9.
If you like our products and services, please help us by posting your review here.

devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Post by devlam »

Strange that they implemented it that way, but now I know I can use it the right way.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 132 guests