Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;

public class assign14_q2


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Pattern");
System.out.println("Type 2 for Series");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
switch (choice) {
case 1:
char ch = 'A';
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(ch + " ");
ch++;
}
System.out.println();
}
break;

case 2:
System.out.print("Enter n: ");
int n = in.nextInt();
double s = 0;
for (int i = 1; i <= n; i=i+2) {
double f = 1;
for (int j = 1; j <= i; j++) {
f *= j;
}
double t = i / f;
s += t;
}
System.out.println("Series Sum = " + s);
break;

default:
System.out.println("Incorrect Choice");
}
}
}

You might also like