Check if number is palindrome or not in base B | Java program to implement the above approach ; Function to check if N in base B is palindrome or not ; Stores the reverse of N ; Stores the value of N ; Extract all the digits of N ; Generate its reverse ; Driver code
class GFG { static boolean checkPalindromeB ( int N , int B ) { int rev = 0 ; int N1 = N ; while ( N1 > 0 ) { rev = rev * B + N1 % B ; N1 = N1 / B ; } return N == rev ; } public static void main ( String [ ] args ) { int N = 5 , B = 2 ; if ( checkPalindromeB ( N , B ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }