Bitwise AND of all the elements of array | Java program to find bitwise AND of all the elements in the array ; Function to calculate bitwise AND ; Initialise ans variable is arr [ 0 ] ; Traverse the array compute AND ; Return ans ; Driver Code ; Function Call to find AND
import java . util . * ; class GFG { static int find_and ( int arr [ ] ) { int ans = arr [ 0 ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { ans = ( ans & arr [ i ] ) ; } return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 5 , 9 , 11 } ; System . out . println ( find_and ( arr ) ) ; } }