Friday, 19 August 2016

Chapter 5 Exercise 24, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

*5.24 (Sum a series) Write a program to sum the following series: 13+35+57+79+911+1113+...+979913+35+57+79+911+1113+...+9799
public class ProgrammingEx5_24 {
 
 public static void main(String[] args) {
  double sum = 0;
 
  for (int i = 1; i <= 97; i += 2) {
   sum += i / (i + 2.0);
  }
   
  System.out.println("Sum of the series is:" + sum);
 }
 
}

No comments :

Post a Comment