write a programme in Java to find the sum of series 1/x+1/x^2+1/x^3+......+1/x^n
Answers
Answered by
2
Write a program in Java to find the sum of the given series.
import java.util.*;
class SeriesSum
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n=sc.nextInt();
System.out.print("Enter the value of x");
double x=sc.nextDouble();
double s=0.0;
for(int i=1;i<=n;i++)
{
s=s+1/Math.pow(x, i);
}
System.out.println("The sum of the series is: "+s);
}
}
Similar questions