Counting even decimal value substrings in a binary string | Java Program to count all even decimal value substring . ; function return count of even decimal value substring ; store the count of even decimal value substring ; substring started with '0' ; increment result by ( n - i ) because all substring which are generate by this character produce even decimal value . ; Driver code
import java . io . * ; class GFG { static int evenDecimalValue ( String str , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '0' ) { result += ( n - i ) ; } } return result ; } public static void main ( String [ ] args ) { String str = "10010" ; int n = 5 ; System . out . println ( evenDecimalValue ( str , n ) ) ; } }