Using a switch statement,write a menu driven program for the following: (to find and display the sum of the series given below) (a) S=1+4+27+256_________+N
Answers
Answered by
1
Explanation:
import java.util.*;
public class menu-driven {
public void main () {
Scanner sc=new Scanner(System.in);
System.out.println("1."+" Sum=1+4+27+256.......... to n terms");
System.out.println("Enter your choice :");
int ch=sc.nextInt();
switch(ch) {
case 1:
System.out.println("Enter the value of n");
int n=sc.nextInt();
int sum=0;
for(int i=1;i<=n;i++) {
sum=sum+(Math.Pow(i,i));
}
System.out.println("Sum of the series="+sum);
break;
default:
System.out.println("Incorrect choice");
}
}
}
Similar questions