Ranajoy Saha wrote:I just changed the data type of factorial variable and the work was done! But I need an explanation. when the data type of factorial variable is int and when I change line 30 to series_calc =(double) (1/factorial); then why isn't the same answer coming as previous one. (The answer is 1.0) I am confused on this part! Dont be angry on me if my question seems silly 'cause I am in school and I have just stated using Java language!
No probs. The answer is basically as fred said, so the result of
1/factorial is an
int. Adding the cast as you have done simply the changes the type of that result; it doesn't change its
value.
BTW, you didn't need to change the type of
factorial. What do you think the result of
1.0/factorial is?
Winston