Divide a number into two parts | Java implementation of the approach ; Function to print the two parts ; Find the position of 4 ; If current character is not '4' but appears after the first occurrence of '4' ; Print both the parts ; Driver code
class GfG { static void twoParts ( String str ) { int flag = 0 ; String a = " " ; char [ ] gfg = str . toCharArray ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( gfg [ i ] == '4' ) { gfg [ i ] = '3' ; a += '1' ; flag = 1 ; } else if ( flag != 0 ) a += '0' ; } str = new String ( gfg ) ; System . out . print ( str + " ▁ " + a ) ; } public static void main ( String [ ] args ) { String str = "9441" ; twoParts ( str ) ; } }