63.8k views
4 votes
Write java program method that takes input as non negative integers and return the number of palindrome or not a palindrome

User Kotu
by
5.3k points

1 Answer

3 votes

Will this help you? Not sure if you ask that your program can take multiple numbers and test each for palindrome, but surely you will need a function like below:


public static boolean isPalindrome(int n) {

String s = Integer.toString(n);

for(int i=0; i<s.length()/2; i++) {

if (s.charAt(i) != s.charAt(s.length()-i-1)) {

return false;

}

}

return true;

}

User Tillda
by
4.6k points