Count pairs with odd Bitwise XOR that can be removed and replaced by their Bitwise OR | Java program for the above approach ; Function to count the number of pairs required to be removed from the array and replaced by their Bitwise OR values ; Stores the count of even array elements ; Traverse the given array ; Increment the count of even array elements ; If the array contains at least one odd array element ; Otherwise , print 0 ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void countPairs ( int arr [ ] , int N ) { int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; } if ( N - even >= 1 ) { System . out . println ( even ) ; return ; } System . out . println ( 0 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 4 , 7 , 2 } ; int N = arr . length ; countPairs ( arr , N ) ; } }