Created
February 25, 2013 01:49
-
-
Save KodeSeeker/5026828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Main { | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
try{ | |
ArrayList<Integer> list= new ArrayList<Integer>(); | |
Scanner input =new Scanner(System.in); | |
int numLines= input.nextInt(); | |
int i=0; | |
while(i<numLines){ | |
int num1=input.nextInt(); | |
for (int j=num1+1;;j++){ | |
if(isPalindrome(j)){ | |
list.add(j); | |
break; | |
} | |
} | |
++i; | |
} | |
for(int k :list){ | |
System.out.println(k); | |
} | |
input.close(); | |
} | |
catch(Exception e){ | |
return; | |
} | |
} | |
public static boolean isPalindrome(int n){ | |
int palindrome=n; | |
int rev=0; | |
int d=0; | |
while(palindrome!=0){ | |
d=palindrome%10; | |
rev=rev*10+d; | |
palindrome=palindrome/10; | |
} | |
if(rev==n){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment