Computer Science, asked by himanshu4828, 1 year ago

Write a program to find the sum of the series (using for loop).
s=1-a+a^2-a^3+ ------ +a^10 using java.

Answers

Answered by parvathypillai
2

Answer:

I hope this helps

Explanation:

import java.io.*;

public class Series

{

  BufferedReader br= new BufferedReader(new InputStreamReader(System.in))

  double s=0

   int a;

   public void show()throws IOException

   {

       System.out.println("Enter the unknown variable");

        a=Integer.parseInt(br.readLine());

        for(int i=0; i<=10; i++)

        {

           if(i%2==0)

           s=s+Math.pow(a,i);

           else

           s=s- Math.pow(a,i);

           }

       System.out.println("The sum of the series is"+ s)

       }

   public void main()throws IOException

   {

      Series s= new Series();

      s.show();

     }

}

Similar questions