Q. Write a java program that checks whether a given number is a palindrome. The program should prompt  the user to enter number.

Palindrome program

				
					class PalindromeExample{
 public static void main(String args[]){
  int r,sum=0,temp;
  int n=455;//It is the number variable to be checked for palindrome

  temp=n;
  while(n>0){
   r=n%10;  //getting remainder
   sum=(sum*10)+r;
   n=n/10;
  }
  if(temp==sum)
   System.out.println("palindrome number ");
  else
   System.out.println("not palindrome");
}
}



				
			

Out Put

Employee Hierarchy:

				
					import java.util.Scanner;

public class PalindromeNumber {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = scanner.nextInt();
        scanner.close();

        if (isPalindrome(number)) {
            System.out.println(number + " is a palindrome number.");
        } else {
            System.out.println(number + " is not a palindrome number.");
        }
    }

    public static boolean isPalindrome(int number) {
        int reversedNumber = 0;
        int originalNumber = number;

        // Reverse the number
        while (number != 0) {
            int digit = number % 10;
            reversedNumber = reversedNumber * 10 + digit;
            number /= 10;
        }

        // Check if the original number is equal to its reverse
        return originalNumber == reversedNumber;
    }
}

				
			

Out Put

prime number

A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. In other words, it remains unchanged when read either from left to right or from right to left. Palindromes are fascinating linguistic and mathematical phenomena that are found in various contexts, including words, sentences, numbers, and even musical compositions.

1. **Words and Phrases**: In linguistics, a palindrome refers to a word or a phrase that reads the same backward as forward. For example, “radar,” “level,” and “madam” are all palindromic words. Palindromic phrases include “A man, a plan, a canal, Panama!” and “Madam, in Eden, I’m Adam.”

2. **Numbers**: In mathematics, a palindrome is a number that remains the same when its digits are reversed. For instance, 121, 1221, and 12321 are all palindromic numbers.

3. **Characteristics**: Palindromes typically exhibit the following characteristics:
– Symmetry: They possess a symmetric structure, where the characters or digits on one side mirror those on the other side.
– Reversibility: They can be read in reverse order without changing their meaning or value.
– Non-dependency: Palindromes do not depend on language or context and can be recognized solely based on their sequential arrangement.

4. **Applications**: Palindromes are not only intriguing linguistic and mathematical constructs but also find applications in various fields:
– Literature and Poetry: Palindromes are often used for wordplay and creative writing in literature and poetry.
– Cryptography: Palindromes can be utilized in encryption and decryption algorithms due to their reversible nature.
– Computer Science: Palindromes are employed in algorithm design and string manipulation tasks in computer science.

5. **Palindrome Types**: Palindromes can vary in complexity and form, including single-word palindromes, palindromic phrases, numeric palindromes, and more intricate palindromic structures.

Overall, palindromes are intriguing linguistic and mathematical constructs that captivate human curiosity and creativity. They offer a glimpse into the symmetry and elegance of language, mathematics, and the natural world.

 
 
Scroll to Top