Removing elements between the two zeros | Java program to delete elements between zeros ; Function to find the string after operation ; use for loop to remove the character between two zeros ; Checking for character Between two zeros ; deleting the character At specific position ; updating the length of the string ; Driver code
import java . util . * ; public class GFG { static String findstring ( String s ) { int n = s . length ( ) ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( s . charAt ( i - 1 ) == '0' && s . charAt ( i + 1 ) == '0' ) ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; i -- ; if ( i > 0 && s . charAt ( i - 1 ) == '0' ) i -- ; n = s . length ( ) ; } } return s ; } public static void main ( String [ ] args ) { String s = "100100" ; System . out . println ( findstring ( s ) ) ; } }