Advertisement
MHSS

numeric palindrome

Sep 30th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.         public static void main (String[] args) throws java.lang.Exception
  11.         {
  12.                 // your code goes here
  13.                 //System.out.println("Hello");
  14.                 Scanner in = new Scanner(System.in);
  15.                 int n = in.nextInt();
  16.                 int no,count;
  17.                 int rev,num,a,b,c;
  18.                 for (int i=0;i<n;i++){
  19.                         num=in.nextInt();
  20.                         count = 0;
  21.                         rev=0;
  22.                         a=num;
  23.                         while (a != 0)
  24.                         {
  25.                 rev = rev*10 + a % 10;
  26.                 a /= 10;
  27.                         }
  28.                        
  29.                         //System.out.println(num);
  30.                         //System.out.println(rev);
  31.                        
  32.                        
  33.                         while (num!=rev){
  34.                                 count++;
  35.                        
  36.                                 num=num+rev;
  37.                                 a=num;
  38.                                 rev=0;
  39.                                 while (a != 0)
  40.                                 {
  41.                         rev = rev*10 + a % 10;
  42.                         a /= 10;
  43.                                 }
  44.                         }
  45.                         System.out.println(count+" "+num);
  46.                 }
  47.         }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement