Palindrome

Palindrome

Problem Description


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.

Logic Test Case 1


Input (stdin)

121


Expected Output


palindrome

Logic Test Case 2


Input (stdin)

13321


Expected Output


not a palindrome




Code Area


import java.io.*;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) 
     {
       int num,reverse=0,original,rem;
       Scanner s=new Scanner(System.in);
       num=s.nextInt();
       original=num;
       while(num!=0)
       { 
         rem=num%10;
         reverse=reverse*10+rem;
         num=num/10;
       } 
       if(original==reverse)
         System.out.println("palindrome");
       else
         System.out.println("not a palindrome");
       }
}

Post a Comment

0 Comments