Problem solved...thanks Jos!!!
Hi all,
I've decided to give it another go and here is my updated code...i think i have method m being called right, but my math within method m is wrong, i can't figure out how to make it right...any help would be greatly appreciated...
/** This program uses a method
* that calculates 1/2 + 2/3 + ... + i/(i+1)
*/
public class Assignment4 {
/* main method */
public static void main(String[] args) {
double mi; //used to catch the return value from method m(i)
//Print the header
System.out.println("i\t\tm(i)\n");
//Print the table
for (int i = 1; i <= 20;i++) {
mi = m(i); //Fill in blank here. Call the method
System.out.println(i+"\t\t"+ mi);
//System.out.println(mi);
} //end for
} //end main
/* define non-void method m(i) here */
public static double m(double key){
double sum;
double i=1;
key = (i/(i+1));
sum =+ key + (i/(i+1));
i++;
//System.out.println(key);
return key;
}
}
//end class
Here is the output i am getting
i m(i)
1 0.5
2 0.6666666666666666
3 0.75
4 0.8
5 0.8333333333333334
6 0.8571428571428571
7 0.875
8 0.8888888888888888
9 0.9
10 0.9090909090909091
11 0.9166666666666666
12 0.9230769230769231
13 0.9285714285714286
14 0.9333333333333333
15 0.9375
16 0.9411764705882353
17 0.9444444444444444
18 0.9473684210526315
19 0.95
20 0.9523809523809523
but the output i'm looking for is:
i m(i)
1 0.5
2 1.1667
…
19 16.4023
20 17.3546