Facebook
From VENKAT NARASIMAM TENNETI, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 66
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.   public static void main(String[] args) {
  6.     Scanner sc = new Scanner(System.in);
  7.     int n = sc.nextInt();
  8.     while (n-- > 0) {
  9.       int num = sc.nextInt();
  10.       System.out.println(nextPalindrome(num + 1));
  11.     }
  12.   }
  13.  
  14.   public static int nextPalindrome(int num) {
  15.     while (!isPalindrome(num)) {
  16.       num++;
  17.     }
  18.     return num;
  19.   }
  20.  
  21.   public static boolean isPalindrome(int num) {
  22.     String str = String.valueOf(num);
  23.     int len = str.length();
  24.     for (int i = 0; i < len / 2; i++) {
  25.       if (str.charAt(i) != str.charAt(len - i - 1)) {
  26.         return false;
  27.       }
  28.     }
  29.     return true;
  30.   }
  31. }