Is there an error with this question?
The solution shows 'double or float' and the explanation gives 'int,long,float or double'
About Question com.enthuware.ets.scjp.v6.2.304 :
Moderator: admin
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.304 :
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.
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.304 :
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.
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.
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.304 :
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.
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.304 :
Strange that they implemented it that way, but now I know I can use it the right way.
Who is online
Users browsing this forum: No registered users and 135 guests