Computer Science, asked by ariko, 1 year ago

write a menu driven program to print depending upon the user if entered A or 1 then frint a factorial of a number or B or 2 to check its a prime no or not how to do this one?


awesomeraghav: what language do you want to use for this program

Answers

Answered by adiric121
1
import java.util.*;
class user_choice
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int i,n,ch,fac=1,p=0;
System.out.println("Enter the number");
n=sc.nextInt();
System.out.println("Enter your choice");
ch=sc.nextInt();
switch(ch)
{
case 1
if(ch==1||ch==A)
{
for(i=1;i<n;i++)
fact=fact*i;
System.out.println("Factorial of the entered number is"+fact);
}
case 2
 if(ch==2||ch==B)
{
for(i=2;i<=n;i++)
{
if(n%i==0)
p++;
}
if(p==1)
System.out.println("Entered number is Prime Number");
else
System.out.println(Entered number is Not Prime Number);
}
}

Similar questions