Menu Close

Palindrome numbers in Java …fcukthecode

Palindromes date back at least to 79 AD, as a palindrome was found as a graffito at Herculaneum, a city buried by ash in that year. This palindrome, called the Sator Square, consists of a sentence written in Latin: “Sator Arepo Tenet Opera Rotas” (“The sower Arepo holds with effort the wheels”).

It is remarkable for the fact that the first letters of each word form the first word, the second letters form the second word, and so forth. Hence, it can be arranged into a word square that reads in four different ways: horizontally or vertically from either top left to bottom right or bottom right to top left.

As such, they can be referred to as palindromatic.

Palindrome on the font at St Martin, Ludgate The palindromic Latin riddle
In girum imus nocte et consumimur igni” (“we go wandering at night and are consumed by fire”) describes the behavior of moths. It is likely that this palindrome is from medieval rather than ancient times.

Input:  
Enter any number: 110011

Output: 
It's Palindrome
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String args[]){
    int num, rem, orig, rev=0;
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter any number:  ");
    num = scan.nextInt();

    orig = num;
    while(num != 0)
    {
        rem = num%10;
        rev = rev*10 + rem;
        num = num/10;
    }

    // check if the original number is equal to its reverse
    if(rev==orig)
    {
        System.out.print("It's Palindrome");
    }
    else{
        System.out.print("Not a Palindrome");
    }
  }
}

INPUT_1:
Enter any number:  121

OUTPUT:
It’s Palindrome


INPUT_2:
Enter any number:  45454

OUTPUT:
It’s Palindrome


INPUT_3:
Enter any number:  8888

OUTPUT:
It’s Palindrome


INPUT_4:
Enter any number:  1010101

OUTPUT:
It’s Palindrome


INPUT_5:
Enter any number:  568965

OUTPUT:
Not a Palindrome


INPUT_6:
Enter any number:  105510

OUTPUT:
Not a Palindrome


INPUT_7:
Enter any number:  105501

OUTPUT:
It’s Palindrome


ILLUSTRATION

Executed using javac in linux terminal