1.

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

Answer»

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");

}

}

}



Discussion

No Comment Found