Find the sum of the series: x1+x2+x3+.....xn. in JAVA
Answers
Answered by
1
Answer:
// Print sum of series 1+x+x2+x3+......+xn
import java.io.*;
import java.lang.Math;
class series1
{
public static void main(String ar[])
{
double i,x=0,n=0,sum=0;
DataInputStream obj= new DataInputStream(System.in);
try
{
System.out.println("Enter the value of x:");
x=Integer.parseInt(obj.readLine());
System.out.println("Enter the value of n:");
n=Integer.parseInt(obj.readLine());
}
catch(IOException e)
{
}
for(i=0;i<=n;i++)
sum=sum+Math.pow(x,i);
System.out.println("Sum is:"+sum);
}
}
MARK ME AS A BRAINILEST
Similar questions
Environmental Sciences,
4 months ago
Math,
4 months ago
English,
4 months ago
Science,
8 months ago
Physics,
1 year ago