If both 4 s and 7 s are there in digit sum , we subtract a 4.
else { a ++ ; sum -= 4 ; } } if ( sum < 0 ) { System . out . print ( " - 1n " ) ; return ; } for ( int i = 0 ; i < a ; i ++ ) System . out . print ( "4" ) ; for ( int i = 0 ; i < b ; i ++ ) System . out . print ( "7" ) ; System . out . println ( ) ; }