Write a menu driven program to perform the following task:-
i. To print the seires 40 30 20 10 0
ii. To find the factorial of a number entered by user.
Answers
Answered by
0
Answer:
Program:-
import java.util.*;
public class Menu
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int ch;
System.out.println("Enter 1 for series");
System.out.println("Enter 2 to display the factorial");
System.out.println("Enter your choice");
ch=in.nextInt();
switch(ch)
{
case 1:
int a;
for(a=40;a>=0;a=a-10)
{
System.out.println(a+ " ");
}
break;
case 2:
int b,fact=1,n;
System.out.println("Enter the number");
n=in.nextInt();
for(b=1;b<=n;b++)
{
fact=fact*b;
}
System.out.println("The factorial of " + n + "=" + f);
break;
default:
System.out.println("Invalid choice");
}
}
}
Similar questions