write a program to check whether the entered number is palindrome or perfect in java(menu driven)
Answers
Answer:
import java.io.*;
class PALINDROME_OR_PERFECT
{
private static int run;
private static int num;
private static int ch;
public static void main(String args[])throws IOException
{
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println("ENTER YOUR CHOICE :");
System.out.println("1 FOR PALINDROME ");
System.out.println("2 FOR PERFECT NUMBER ");
ch=Integer.parseInt(input.readLine());
if(ch==1)
{
System.out.println("ENTER A NUMBER FOR FINDING WHETHER IT IS A PALINDROME");
num=Integer.parseInt(input.readLine());
int d;
int rev=0;
int num1=num;
do
{
d=num%10;
rev=(rev*10)+d;
num=num/10;
}while(num!=0);
if(num1==rev)
System.out.println("IT IS A PALINDROME");
else
System.out.println("IT IS NOT A PALINDROME");
}
else if(ch==2)
{
System.out.println("ENTER A NUMBER FOR FINDING WHETHER IT IS A PERFECT NUMBER");
num=Integer.parseInt(input.readLine());
int i=1;
int sum=0;
while(i<num)
{
if(num%i==0)
sum=sum+i;
i++;
}
if(sum==num)
System.out.println("IT IS A PERFECT NUMBER");
else
System.out.println("IT IS NOT A PERFECT NUMBER");
}
else
System.out.println("ENTERED WRONG DATA");
}
}