Computer Science, asked by reconectmyself, 13 hours ago

Write a menu driven program to find the sum of the given series: i) 1 + 4 + 9 + 16 +… … up to n terms​

Answers

Answered by kishansavani
1

Answer:

import java.util.Scanner;

public class SeriesMenu

{

   public static void main(String args[]) {

       Scanner in = new Scanner(System.in);

       System.out.println("Type 1 to print series");

       System.out.println("0, 3, 8, 15, 24,....to n terms");

       System.out.println();

       System.out.println("Type 2 to find sum of series");

       System.out.println("(1/2) + (3/4) + (5/6) + (7/8) +....+ (19/20)");

       System.out.println();

       System.out.print("Enter your choice: ");

       int choice = in.nextInt();

       switch (choice) {

           case 1:

               System.out.print("Enter n: ");

               int n = in.nextInt();

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

                   System.out.print(((i * i) - 1) + " ");

               System.out.println();

               break;

               

           case 2:

               double sum = 0;

               for (int i = 1; i <= 19; i = i + 2)

                   sum += i / (double)(i + 1);

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

               break;

               

           default:

               System.out.println("Incorrect Choice");

               break;

       }

   }

}

Answered by subhashkhadse12
0

Answer:

36

Explanation:

this answer is very different

Similar questions