Computer Science, asked by sy4451946, 8 months ago

write a program in Java to accept the user that the number is palindrome or perfect

Answers

Answered by singhjaspal8456
8

Answer:

Brainly.in

What is your question?

remantkakkar7752

19.05.2019

Computer Science

Secondary School

+5 pts

Answered

Write a menu driven program to accept a number from the user and check whether it is a palindrome number or a perfect number

2

SEE ANSWERS

Log in to add comment

Answer

4.1/5

37

jaylalsjc

Ambitious

21 answers

730 people helped

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");

}

}

}

Explanation:

hope it will help you....☺️☺️

have a nice day......

Similar questions