Replace ' ? ' to convert given string to a binary string with maximum count of '0' and "10" | Java program to implement the above approach ; Function to maximize count of 0 and 10 by replacing character ' ? ' to '0' or '1' ; Traverse the given String ; If current character is ' ? ' ; Replace str [ i ] to '0' ; Driver Code ; Given String
class GFG { static void findMaxOccurence ( char [ ] str , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ? ' ) { str [ i ] = '0' ; } } System . out . print ( str ) ; } public static void main ( String [ ] args ) { String str = "10?0?11" ; int N = str . length ( ) ; findMaxOccurence ( str . toCharArray ( ) , N ) ; } }