XOR and OR of all N | Java program to find the XOR and OR of all palindrome numbers of N digits ; Function to check if a number is palindrome or not ; Convert the num n to string ; Iterate over string to check whether it is palindromic or not ; Function to find XOR of all N - digits palindrome number ; To store the XOR and OR of all palindromic number ; Starting N - digit palindromic number ; Ending N - digit palindromic number ; Iterate over starting and / ending number ; To check if i is palindromic or not ; Print the XOR and OR of all palindromic number ; Driver Code
class GFG { static boolean ispalin ( int num ) { String s = Integer . toString ( num ) ; int st = 0 , ed = s . length ( ) - 1 ; while ( st <= ed ) { if ( s . charAt ( st ) != s . charAt ( ed ) ) return false ; st ++ ; ed -- ; } return true ; } static void CalculateXORandOR ( int n ) { int CalculateXOR = 0 ; int CalculateOR = 0 ; int start = ( int ) Math . pow ( 10 , n - 1 ) ; int end = ( int ) Math . pow ( 10 , n ) - 1 ; for ( int i = start ; i <= end ; i ++ ) { if ( ispalin ( i ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } System . out . print ( " XOR ▁ = ▁ " + CalculateXOR ) ; System . out . println ( " ▁ OR ▁ = ▁ " + CalculateOR ) ; } public static void main ( String [ ] args ) { int n = 4 ; CalculateXORandOR ( n ) ; } }