I've written this code for a method that take an integer number and return the sum of a series.
this is the formula of the series
m(i)=4(1- 1/3 + 1/5 -1/7 + 1/9 - 1/11 + 1/13 - ................. - 1/(2i-1) + 1/(2i+1)) and this is the code
The problem is that the program take too many time to run and doesn't give true result.
i couldn't trace the error, and i hope helping me.
thanks in advance.
I Hear I Forget, I See I Remember, I Do I Understand.
You've defined the upper limit of your loop in terms of "i", but of course "i" changes with every loop iteration. I think you meant to use "n" there, yes?
Thanks a lot My friends Ernest Friedman-Hill, Paul Clapham, and Luigi Plinge
you really help me, and i will take more attention to avoid Falling through such errors.
I Hear I Forget, I See I Remember, I Do I Understand.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet wrote:It's a double so that isn't going to work.
Aaaargh! I didn't notice that. Even Double.MIN_VALUE / 2 won't work because you reach a value where the precision is < 2, so d + 2 == d to the JVM, and the value will remain the same for ever.