Number of subsequences in a given binary string divisible by 2 | Java implementation of the approach ; Function to return the count of the required subsequences ; To store the final answer ; Multiplier ; Loop to find the answer ; Condition to update the answer ; updating multiplier ; Driver code
class GFG { static int countSubSeq ( String str , int len ) { int ans = 0 ; int mul = 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) ans += mul ; mul *= 2 ; } return ans ; } public static void main ( String [ ] args ) { String str = "10010" ; int len = str . length ( ) ; System . out . print ( countSubSeq ( str , len ) ) ; } }