Remove one bit from a binary number to get maximum value | Java program to find next maximum binary number with one bit removed ; Function to find the maximum binary number ; Traverse the binary number ; Try finding a 0 and skip it ; Driver code ; Get the binary number ; Find the maximum binary number
import java . io . * ; class GFG { static int printMaxAfterRemoval ( String s ) { boolean flag = false ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '0' && flag == false ) { flag = true ; continue ; } else System . out . print ( s . charAt ( i ) ) ; } return 0 ; } public static void main ( String [ ] args ) { String s = "1001" ; printMaxAfterRemoval ( s ) ; } }