title: Sum Series 23 45 67 89 Upto N Terms
signature: class Solution {
  
      public Double sumSeries23456789UptoNTerms(Integer n) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Double expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(49, 0.7803986631477524);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(4, -0.16507936507936516);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(60, -0.21050375120783382);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(90, -0.21185466678122022);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(96, -0.2120245854859959);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(29, 0.7770671416747363);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(86, -0.21172836828074082);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(47, 0.780190394898247);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(77, 0.7821931668684383);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(87, 0.7825573460049735);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Double expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n),expected);
      }
      
      public boolean validateSolution(Double actual, Double expected){
          return Math.abs(actual - expected) < 1e-09;
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def sum_series_23_45_67_89_upto_n_terms(n):
      i = 1
      res = 0.0
      sign = True
      while (n > 0):
          n = (n - 1)
          if sign:
              sign = False
              res = (res + ((i + 1) / (i + 2)))
              i = (i + 2)
          else:
              sign = True
              res = (res - ((i + 1) / (i + 2)))
              i = (i + 2)
      return res
source_cpp: double sum_series_23_45_67_89_upto_n_terms(int n) {
    int i = 1;
    double res = 0.0;
    bool sign = true;
    while ( n > 0 ) {
      n --;
      if ( sign ) {
        sign = ! sign;
        res = res + ( double ) ++ i / ++ i;
      }
      else {
        sign = ! sign;
        res = res - ( double ) ++ i / ++ i;
      }
    }
    return res;
  }