title: How To Find The Nearest Palindrome Number?
body: <p>Well i tried to write a program in java to find the palindrome , someone asked me to add a twist in that and the twist goes like this we have to find whether the number is palindrome or not if not then we have to find the nearest palindrome number. For example if the number entered is 37 then there are two numbers which can be palindrome near it one is 33 and the other is 44, but the nearer is 33 so here 33 is the answer. I tried lot to write it but without success :(</p>
  
  <pre><code>import java.io.*;  
  public class NearestPalindrome {  
  static int i,j,n,m,f,r=0,g,p1,p2,c1=0,c2=0,a;  
  static boolean k;  
  public static void main (String []agrs)throws IOException  
  {
     BufferedReader A = new BufferedReader(new InputStreamReader(System.in));  
     System.out.println("This Program Is Created For Checking Whether The Number Entered Is Palindrome, If Not Find The Nearest Palindrome..");  
     System.out.println("Please Enter Number:-");  
     n=Integer.parseInt(A.readLine());
     f=n;  
     NearestPalindrome.Palindrome(f);  
     if(r==f)
     {System.out.println("This Is A Palindrome Number:-"+r);}
     else
     {
         for(i=n;((c1==1)&amp;&amp;(c2==1));i--)
         {
             NearestPalindrome.Palindrome(i);  
             NearestPalindrome.Palindrome(j);  
             if(k=true)  
             { if(r==i)  
             {   p1=i;  
             c1++;  
             }  
             if(r==j)  
                 {p2=j;  
                 c2++;  
                 }  
                 }  
             }  
         if((n-p1)&gt;(p2-n))    
         {
          System.out.println("The Nearest Palindrome Is:-"+p2);  
         }  
         else  
          System.out.println("The Nearest Palindrome Is:-"+p1);  
  
         }  
  
     }  
  public static boolean Palindrome (int x)
  {
  
  
      for(i=0;x&gt;0;i++)
         {
             m=x%10;
             r=r*10+m;
             x=x/10;   
         }  
      if(n==r)
      {k=true;}
      else
          k=false;
  return k;
  }  
  </code></pre>
  
  <p>}  </p>