4-7 Series
Post date: Feb 12, 2014 9:54:52 PM
/*Write a program to calculate the sum of the following series as shown below
Sum=1+x/2+x^2/3+x^3/4+⋯+x^n/(n+1)
*/
package series;
import java.util.Scanner;//Needed for class Scanner
public class Series
{
public static void main(String[] args)
{
// Create a Scanner object for keyboard input.
Scanner input=new Scanner(System.in);
System.out.print("Enter the value of n : ");
double n=input.nextDouble();
System.out.print("Enter the value of x : ");
double x=input.nextDouble(),sum=0;
while(n>=0)
{
sum+=Math.pow(x,n)/(n+1);
n--;
}
System.out.println("Sum of the series = "+sum);
}
}