Computer Science, asked by harshraj7529, 3 months ago

Write a menu driven program as per the following:-
1) Method named palindrome to check whether the entered number is palindrome or not.
2) Method named Armstrong to check entered number is Armstrong or not.
3) Method named composite to check whether entered number is composite number or not.


Call the above methods in main method using switch case as per the choice.








Irrelevant answers 10 answers will be reported
Correct answerer will be marked brainliest and 50 thanks

Attachments:

Answers

Answered by Anonymous
0

Write a menu driven program as per the following:-

1) Method named palindrome to check whether the entered number is palindrome or not.

2) Method named Armstrong to check entered number is Armstrong or not.

3) Method named composite to check whether entered number is composite number or not.

Call the above methods in main method using switch case as per the choice.

Irrelevant answers 10 answers will be reported

Correct answerer will be marked brainliest and 50

Answered by atrs7391
1

/*

Project Type: Brainly Answer

Date Created: 17-02-2021

Date Edited Last Time: ---NIL---

Question Link: https://brainly.in/question/34499457

Question: Write a menu driven program as per the following:-

1) Method named palindrome to check whether the entered number is palindrome or not.

2) Method named Armstrong to check entered number is Armstrong or not.

3) Method named composite to check whether entered number is composite number or not.

Call the above methods in main method using switch case as per the choice.

Program Created By: atrs7391

Programming Language: Java

Language version (When program created or last edited): jdk-15.0.2

*/

package Brainly_Answers;

import java.util.Scanner;

public class Menu_Driven_Program_2 {

   static void Palindrome() {

       Scanner sc = new Scanner (System.in);

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

       int num = sc.nextInt();

       int reversedInteger = 0, remainder, originalInteger;

       originalInteger = num;

       while( num != 0 )

       {

           remainder = num % 10;

           reversedInteger = reversedInteger * 10 + remainder;

           num  /= 10;

       }

       if (originalInteger == reversedInteger)

       {

           System.out.println("Given number is a palindrome number.");

       }

       else

       {

           System.out.println("Given number is not a palindrome number.");

       }

   }

   static void Armstrong() {

       Scanner sc = new Scanner (System.in);

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

       int num = sc.nextInt();

       int originalNumber, remainder, result = 0;

       originalNumber = num;

       while (originalNumber != 0)

       {

           remainder = originalNumber % 10;

           result += Math.pow(remainder, 3);

           originalNumber /= 10;

       }

       if(result == num)

       {

           System.out.println("Given number is an Armstrong number.");

       }

       else

       {

           System.out.println("Given number is not an Armstrong number.");

       }

   }

   static void Composite() {

       Scanner sc = new Scanner (System.in);

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

       int n = sc.nextInt();

       int c=0;

       for(int i=2;i<n;i++)

       {

           if(n%i==0)

           {

               c++;

           }

       }

       if(c>1)

       {

           System.out.println("Given number is Composite number.");

       }

       else

       {

           System.out.println("Given number is not a Composite number.");

       }

   }

   public static void main(String[] args) {

       Scanner sc = new Scanner (System.in);

       System.out.println("Enter 1 to check whether the number is Palindrome number or not.");

       System.out.println("Enter 2 to check whether the number is Armstrong number or not.");

       System.out.println("Enter 3 to check whether the number is Composite number or not.");

       int op = sc.nextInt();

       switch (op) {

           case 1 -> Palindrome();

           case 2 -> Armstrong();

           case 3 -> Composite();

           default -> System.out.println("Wrong Input, cannot execute program.");

       }

   }

}

Similar questions