title: Compute a series
body: <p>Assignment: Write a method to compute the following series:
  m(i) = 1 - (1/2) + (1/3) - (1/4) + (1/5) - ... + ((-1)^(i+1))/i</p>
  
  <p>Write a test program that displays the following code:</p>
  
  <pre><code>i:       m(i):
  5        0,78333
  10       0,64563
  ..       ..
  45       0,70413
  50       0,68324
  </code></pre>
  
  <p>I've tried for a couple of hours now, and I just can't think of how to solve this. Maybe I'm just stupid haha :)</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>package computingaseries;
  
  public class ComputingASeries {
  
      public static void main(String[] args) {
  
          System.out.println("i\t\tm(i)");
          for (int i = 5; i &lt;= 50; i += 5) {
              System.out.println(i + "\t\t" + m(i));
          }
      }
  </code></pre>
  
  <p>UPDATED:</p>
  
  <pre><code>    public static double m(int n) {
          double tal = 0;
          double x = 0;
  
          for (int i = 1; i &lt;= n; i += 1) {
              if (i == 1) {
                  x = 1 - ((Math.pow(-1, (i + 1))) / i);
              } else {
                  x = ((Math.pow(-1, (i + 1))) / i);
              }
          }
          tal += x;
  
          return tal;
  
      }
  }
  </code></pre>
  
  <p>My wrong output:</p>
  
  <pre><code>i       m(i)
  5       0.2
  10      -0.1
  15      0.06666666666666667
  20      -0.05
  25      0.04
  30      -0.03333333333333333
  35      0.02857142857142857
  40      -0.025
  45      0.022222222222222223
  50      -0.02
  </code></pre>