Computer Science, asked by tsohan, 4 months ago

write a menu driven program in Java to accept a number and check is it a prime number or a palindrome number.​

Answers

Answered by Innocentgirl58
7

Answer:

IMPORT JAVA.UTIL.*;

CLASS MENU1

{

 VOID MAIN()

 {

     SCANNER SC=NEW SCANNER(SYSTEM.IN);

    SYSTEM.OUT.PRINTLN("1. CHECK NUMBER FOR PALINDROME");

   SYSTEM.OUT.PRINTLN("2. CHECK NUMBER FOR PERFECT");

  SYSTEM.OUT.PRINTLN("ENTER YOUR CHOICE");

  INT CH=SC.NEXTINT();

  SYSTEM.OUT.PRINTLN("ENTER NUMBER");

 INT N=SC.NEXTINT();

SWITCH(CH)

{

     CASE 1:

     INT R=0,D,BK=N,

    WHILE(BK!=0)

{

      D=BK%10;

R=R*10+D;

BK=BK/10;

}

IF(R==N)

SYSTEM.OUT.PRINTLN("NUMBER IS PALINDROME");

ELSE

SYSTEM.OUT.PRINTLN("NUMBER IS NOT PALINDROME");

}

BREAK;

CASE 2;

INT I,S=0,

FOR(I=0;I<N;I++)

{

   IF(N%I==0)

S=S+I;

}

IF(S==N)

SYSTEM.OUT.PRINTLN("NUMBER IS PERFECT");

ELSE

SYSTEM.OUT.PRINTLN("NUMBER IS NOT PERFECT");

BREAK;

DEFAULT:

SYSTEM.OUT.PRINTLN("INVALID CHOICE");

 }

}

}

Similar questions
Math, 2 months ago