This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Double Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Double Question" Watch "Double Question" New topic
Author

Double Question

Vidya sumanasekara
Greenhorn

Joined: Feb 03, 2011
Posts: 10


Out put:-
1.0 1.5

Why it gives two different output...
help me....
anirudh jagithyala
Ranch Hand

Joined: Dec 07, 2010
Posts: 41
for d1=3/2
int(operation)int is int

int/int=int therefore 3/2=1.5(int)=1
d1=1 i.e., d1=1.0;

but incase of d2=3/2d
int(operation)double=double

int/double=double;;;;double/int=double
therefore 3/2d=3/2.0=1.5(double)=1.5
d2=1.5


Hope it is clear
Vidya sumanasekara
Greenhorn

Joined: Feb 03, 2011
Posts: 10
anirudh jagithyala wrote:

int/double=double;;;;double/int=double
therefore 3/2d=3/2.0=1.5(double)=1.5
d2=1.5


Hope it is clear


Oh....I got it...Thanks. the case is "2d"...
 
wood burning stoves
 
subject: Double Question
 
Similar Threads
Variables[code]
if(0.0 == -0.0) - Sample question
Long.MAX_VALUE and double conversion
Issue adding double value
Double Boolean Operations