I have to write a code to do the following:
Write a method to compute the following series:
m(i) = 4(1-1/3+1/5-1/7+1/9-1/11+...+1/(2i-1)-1/(2i+1)
Write a test program that displays the following table:
i m(i)
10 3.04184
20 3.09162
...
100 3.13159
This is my code so far, but i keep outputting only 0's /: If anybody can help me, it would be much appreciated!
public class Practice {
public static void main(String[] args) {
int i = 0;
System.out.println("i \t m(i)");
while (i <= 100) {
double seriesNum = series(i);
System.out.print(i + "\t" + seriesNum + "\n");
i += 10;
}
}
public static double series(double j) {
double number = 0;
while (j % 10 != 0) {
number = 4 * (1 / (2 * j - 1) - 1 / (2 * j + 1));
j += 1;
}
return number;
}
}

New Topic/Question
Reply



MultiQuote





|