Computer Science, asked by devilabdullah69, 4 months ago

Write a menu driven program to accept a number and check whether it is a prime or Armstrong number.
a) Prime Number : A number is called Prime if it is divisible by 1 and the number itself. Example: 5, 7, 11 etc.​

Answers

Answered by ankita3998
4

Answer:

import java.util.*;

public class Check

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int n;

System.out.println("Enter 1 for prime or 2 for armstrong");

n=sc.nextInt();

switch(n)

{

case 1:

int m,i,c=0;

System.out.println("Enter a number");

m=sc.nextInt();

for(i=1;i<=m;i++)

{

if(m%i==0)

c++;

}

if(c==2)

System.out.println("Prime");

else

System.out.println("Not prime");

break;

case 2:

int a,r,s=0,p;

System.out.println("Enter a number");

a=sc.nextInt();

p=a;

do

{

r=a%10;

s=s+r*r*r;

n=n/10;

}

while(a!=0);

if(s==p)

System. out.println("Armstrong");

else

System. out.println("Not");

break;

default:

System. out.println("Wrong choice");

}

}

}

Similar questions