Computer Science, asked by sandipkeshri765, 4 months ago

write a program in java to print the given series in java​

Attachments:

Answers

Answered by mpd20700
0

Answer:

import java.util.*;

public class Main {

  public static void main(String[] args) {

        Scanner sc=new Scanner (System.in);

        System.out.println("Enter the number of terms you want that is the value of n");

        int n=sc.nextInt();

        double a=4.0;

        double b=3.0;

        double sum=0;

        for(int i=1;i<=n;i++)

        {

            if(i%2==0)

            {

                sum=sum+(a/b);

            }

            else

            {

                sum=sum-(a/b);

            }

            b=b+2;

        }

        System.out.println("Sum="+sum);

        sc.close();

 }

}

Similar questions