public class NextPalindromeNumber {
public static void main(String[] args) {
int n = 121;
int nextPalindrome = 0;
int temp = n;
for (int i = temp + 1; i >= temp; i++) {
temp = i;
nextPalindrome = 0;
while (temp != 0) {
int q = temp % 10;
nextPalindrome = nextPalindrome * 10 + q;
temp = temp / 10;
}
if (nextPalindrome == i) {
break;
}
}
System.out.println(nextPalindrome);
}
}
Comments
Post a Comment