Largest sub | Java implementation of the approach ; Function to return the largest substring divisible by 2 ; While the last character of the string is '1' , pop it ; If the original string had no '0' ; Driver code
class GFG { static String largestSubStr ( String s ) { while ( s . length ( ) != 0 && s . charAt ( s . length ( ) - 1 ) == '1' ) s = s . substring ( 0 , s . length ( ) - 1 ) ; if ( s . length ( ) == 0 ) return " - 1" ; else return s ; } public static void main ( String [ ] args ) { String s = "11001" ; System . out . println ( largestSubStr ( s ) ) ; } }