Computer Science, asked by sayantikapramanik06, 4 days ago

Write a menu based program to input a number and based on the user’s choice, check whether it is a Palindrome number or a Neon number.​

Answers

Answered by ButterflyUSR
3

Answer:

import java.util.Scanner;

public class KboatPalinOrPerfect

{

   public static void main(String args[]) {

       Scanner in = new Scanner(System.in);

       System.out.println("1. Palindrome number");

       System.out.println("2. Perfect number");

       System.out.print("Enter your choice: ");

       int choice = in.nextInt();

       System.out.print("Enter number: ");

       int num = in.nextInt();

       switch (choice) {

           case 1:

           int copyNum = num;

           int revNum = 0;

           while(copyNum != 0) {

               int digit = copyNum % 10;

               copyNum /= 10;

               revNum = revNum * 10 + digit;

           }

           if (revNum == num)  

               System.out.println(num + " is palindrome");

           else

               System.out.println(num + " is not palindrome");

           break;

           case 2:

           int sum = 0;

           for (int i = 1; i <= num / 2; i++) {

               if (num % i == 0) {

                   sum += i;

               }

           }

           if (num == sum)  

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

           else

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

           break;

           default:

           System.out.println("Incorrect Choice");

           break;

       }

   }

}

MARK ME BRAINLIEST

Answered by alpeshchaudhary05548
1

Answer:

import java.io.*;  class number  {  public static void main()throws IOException  {  InputStreamReader IR=new InputStreamReader(System.in);  BufferedReader br=new BufferedReader(IR);  System.out.println(“Press 1 for Palindrome Number”);  System.out.println(“Press 2 for Perfect Number”);  System.out.println(“Enter your choice”); int ch=Integer.parseInt(br.readLine());  int num1, num2;  switch(ch)  {  case 1:  System.out.println(“Enter the Number :”);  num1=Integer.parseInt(br.readLine());  int rev=0; int  x=num1; //duplicate copy while (x!=0) {  rev=rev*10+x%10; x=x/10;  }  if(rev==num1)  {  System.out.println(“The number is Palindrome”);  }  else  {  System.out.println(“The Number is Not Palindrome”);  }  break;  case 2:  System.out.print(“Enter the Number :”);  num2=Integer.parseInt(br.readLine());  int sum=0;  for(int i=1; i

Similar questions