Computer Science, asked by garima23agarwal, 9 months ago

. Write a menu driven program to perform the following tasks by using Switch case statement: 2. To find the sum of the series: S = ½ + ¾ + 5/6 + 7/8 + ………………………. to n terms.

Answers

Answered by sp7227730
3

Answer:

Solution:

import java.io.*;

public class MenuSeries

{

public static void main(String args[])throws IOException

{

InputStreamReader in=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(in);

char choice;

int n,i;

double s=0;

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

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

System.out.println("A or a for series 0,3,8,15,24……");

System.out.println("B or b fro series s=1/2+3/4+5/6+..+19/20");

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

choice=(char)br.read();

switch(choice)

{

case 'A':

case 'a':

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

{

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

}

break;

case 'B':

case 'b':

for(i=2;i<=20;i+=2)

{

s=s+(double)(i-1)/i;

}

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

break;

default:

System.out.print("Wrong choice.....");

}

}

}

Explanation:

If my answer is correct please mark me as brainliest and give me a like

Similar questions