To check a number is palindrome or not without using any extra space | Java program to find number is palindrome or not without using any extra space ; Function to check if given number is palindrome or not without using the extra space ; Find the appropriate divisor to extract the leading digit ; If first and last digit not same return false ; Removing the leading and trailing digit from number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Driver code
public class GFG { static boolean isPalindrome ( int n ) { bool isPalindrome ( int n ) { int divisor = 1 ; while ( n / divisor >= 10 ) divisor *= 10 ; while ( n != 0 ) { int leading = n / divisor ; int trailing = n % 10 ; if ( leading != trailing ) return false ; n = ( n % divisor ) / 10 ; divisor = divisor / 100 ; } return true ; } public static void main ( String args [ ] ) { if ( isPalindrome ( 1001 ) ) System . out . println ( " Yes , ▁ it ▁ is ▁ Palindrome " ) ; else System . out . println ( " No , ▁ not ▁ Palindrome " ) ; } }