Number of sub | Java implementation of the approach ; Function to return the count of the required substrings ; To store the final answer ; Loop to find the answer ; Condition to update the answer ; Driver code
class GFG { static int countSubStr ( String str , int len ) { int ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) ans += ( i + 1 ) ; } return ans ; } public static void main ( String [ ] args ) { String str = "10010" ; int len = str . length ( ) ; System . out . println ( countSubStr ( str , len ) ) ; } }