Print all distinct even and odd prefix Bitwise XORs of first N natural numbers | Java approach for the above approach ; Print all distinct even & odd prefix Bitwise XORs from 1 to N ; Print the even number ; Print the odd number ; Driver Code
class GFG { static void evenOddBitwiseXOR ( int N ) { System . out . print ( " Even : ▁ " + 0 + " ▁ " ) ; for ( int i = 4 ; i <= N ; i = i + 4 ) { System . out . print ( i + " ▁ " ) ; } System . out . print ( "NEW_LINE"); System . out . print ( " Odd : ▁ " + 1 + " ▁ " ) ; for ( int i = 4 ; i <= N ; i = i + 4 ) { System . out . print ( i - 1 + " ▁ " ) ; } if ( N % 4 == 2 ) System . out . print ( N + 1 ) ; else if ( N % 4 == 3 ) System . out . print ( N ) ; } public static void main ( String [ ] args ) { int N = 6 ; evenOddBitwiseXOR ( N ) ; } }