Computer Science, asked by ruby932, 30 days ago

write a menu driven program to print sum of series s=1+12+123+.….n terms

Don't spam! ​

Answers

Answered by pps147265
1

Answer:

import java.util.Scanner; public class KboatSeriesMenu { 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; } } }

Similar questions