java - Having trouble getting my output to show up in my terminal while using methods -


having problem dealing methods. simple program, can't seem data print terminal

here's code:

public class method {     public static void main( string args[] )     {         double result = 0;         int i;         system.out.println("i" + "\t\t" +  "m(i)");         system.out.println("-------------------");         //columns , header      }     public double thesum(int i, double result)     {         for(i=0; < 21; i++)         {             system.out.print(i + "\t\t" + result + "\n");             result +=(double) (i + 1)/(i+2);                // computing data         }         return result;     }     } 

everything compiles, output prints headers... think bottom method may wrong, not sure where.

sample output: 1        0.5 2        1.16 ... 19       16.40 20       17.35 

you need call method print output

    public static void main( string args[] )         {                 double result = 0;             int i=0;             system.out.println("i" + "\t\t" +  "m(i)");             system.out.println("-------------------");             //columns , header            method d=new method();             d.thesum(i,result);  } 

output

i       m(i) ------------------- 0       0.0 1       0.5 2       1.1666666666666665 3       1.9166666666666665 4       2.716666666666667 5       3.5500000000000003 6       4.4071428571428575 

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 -