//.................................................................... //--------------THIS PROGRAM COMPUTES THE NEXT PALINDROME FOR -------- //--------------------A GIVEN NUMBER x if x is not Palindrome---------. //-------------------------------------------------------------------- //-----------------------THISIS VERY VERY INEFFICIENT PROGRAM--------- class Next_palindrome { public static void main(String args[]) { // Caution : this program is very inefficeint, it will take huge // time to complete for large value of x. So give small value of x // For large value of x, please use "CTRL+c" to break the execution. // YOU ARE ENCOURAGED TO DESIGN AN EFFICIENT PROGRAM FOR THIS PROBLEM long x=1000110002L; // given number n. Assign it some value. long temp; // variable for storing x temporarily; temp=x; long d=0; // variable for storing digits of n temporarily long reverse; // the variable which will eventually store the reversed // number n reverse=0; boolean flag; flag=false; while(flag==false) { long n=temp; reverse=0; while(n>0) { d = n%10; reverse = reverse*10 + d; n = n/10; } flag=(reverse==temp); temp=temp+1; } System.out.println("the next palindrome of "+x+" is : "+reverse); } }