Check whether bitwise AND of a number with any subset of an array is zero or not | Java program to check whether bitwise AND of a number with any subset of an array is zero or not ; Function to check whether bitwise AND of a number with any subset of an array is zero or not ; variable to store the AND of all the elements ; find the AND of all the elements of the array ; if the AND of all the array elements and N is equal to zero ; Driver Code
import java . io . * ; public class GFG { static void isSubsetAndZero ( int array [ ] , int length , int N ) { int arrAnd = array [ 0 ] ; for ( int i = 1 ; i < length ; i ++ ) { arrAnd = arrAnd & array [ i ] ; } if ( ( arrAnd & N ) == 0 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int array [ ] = { 1 , 2 , 4 } ; int length = array . length ; int N = 3 ; isSubsetAndZero ( array , length , N ) ; } }