Math, asked by AhmadTaha6524, 9 months ago

Write a menu driven program to accept a number from the user and check whether it is (1) prime number ( a number is said to be prime, if it divisible by 1 and itself),(2) neon number(a number is said to be a neon ,if thr sum of the digits of the square of the number is equal to the number itself),(3)perfect number (a number is said to be a perfect, if the sum of the factors (excluding the number itself)is the same as the original number)

Answers

Answered by soniamasown
24

Answer:

import java.util.*;

class number{

static void f(){

Scanner sc=new Scanner(System.in);

System.out.println("Enter 1:Prime number \t 2:Neon number \t 3:Perfect number"); //Write these in 1line only

int choice=sc.nextInt();

switch(choice){

case 1:

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

int n=sc.nextInt();

int a,c=0;

for(a=1;a<=n;a++){

c++;

}

if(c%2==0){

System.out.println("It is a prime number");

}

else

System.out.println("It is a prime number");

break;

case 2:

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

int num=sc.nextInt();

int temp=num;

int d,sum=0;

int sq=num*num;

while(sq>0)

{

d=sq%10;

sq=sq/10;

sum=sum+d;

}

if(sum==temp)

System.out.println("It is a neon number");

else

System.out.println("It is not a neon number");

break;

case 3:

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

int number=sc.nextInt();

int t=number;

int x,s=0;

for(x=1;x<number;x++){

if(number%x==0)

s=s+x;

}

if(s==t)

System.out.println("It is a perfect number");

else

System.out.println("It is not a perfect number");

break;

}}}

Please follow me at least for these efforts

Similar questions