public class Equation
{
   public static void main (String[] args)
   {
      Equation eqn = new Equation();
      
      eqn.ShowAnswer( eqn.CalcAnswer(3) );   
   }
   
   private double CalcAnswer(int n)
   {
      //
      // We have an answer which needs to be double. Looking at the equation
      // this answer should initially be set to 1.0, and then set by the loop.
      //
      double answer = 1.0;
      
      //
      // Before proceeding, do a little error checking...
      if ( n < 2 ) return 0.0;
      
      for ( int i = 2; i <= n; i++ )
      {
         if ( i % 2 == 0 ) answer -= 1.0/i; // Note: dividing a double by i.
         else              answer += 1.0/i;
      
         //
         // Alternatives:
         // 
         // answer += ( i % 2 == 0 ) ? -1.0 / i : 1.0 / i;
         //
         // answer += (( i % 2 == 0 ) ? -1.0 : 1.0 ) / i;
         //
      }
      
      return answer;
   }
   
   private void ShowAnswer(double d)
   {
      System.out.println("The answer is: " + d);
   }
}