java - creating a method in using a (sum series) Write a method to compute the following series -


then output looks followed:                          m(i) 1                         0.5 2                         1.1667 ...  19                        16.4023 20                        17.3546     /**  * write description of class fiveonethree here.  *   * @author (your name)   * @version (a version number or date)  */  public class homework {     public static void main( string args[] )    {       double value = 0;       system.out.println("i" + "\t\t" +  "m(i)");       system.out.println("-------------------");       for( int i=0; < 21; i++)       {          system.out.println( + " \t\t " + value + "\n" );          value += ((double) + 1)/(i+2);       }    } } 

i have output correct , everything, professor wants in method. find methods difficult, created simple loop. directions are: write method compute following series: 1/2+2/3.......+i/i+1

i'm guessing he/she wants method looks like

public double thesum(int n) {     ... } 

where n number of terms (so last term n/(n+1)). main method call thesum(??) value parameter used n. of course mean you're doing computation print table, don't worry that. (maybe should call m instead of thesum since called function. don't one-letter function names.)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -