Write a program which will remove any given character from string .using string builder

it is half wrong
import java.util.Scanner;

public class REMOVE {

public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
    String str=input.nextLine();
    int len=str.length();
    char character=input.next().charAt(0);
    StringBuilder sb=new StringBuilder(str);
    for(int i=0;i<len;i++) {
    char ch=sb.charAt(i);
    if(character==ch) {
    	sb.delete(i,i+1);
    	System.out.println(sb);
    	len--;
    	i=0;
    	System.out.println(len);
    }
    }
    if(character==sb.charAt(len)) {
    	System.out.println("EMPTY STRING");
    }
    else {
    	 String sbr=sb.toString();
    	 int leng=sbr.length();
    	for(int i=0;i<=leng;i++) {
		    System.out.print(sbr.charAt(i));
    	}
    }
}

}

let , string=“ABCDE”

AND WE WANT TO REMOVE EVERY CHARACTER ONE BY ONE USING STRING BUILDER , HOW CAN WE DO THAT.

@KUNAL.SHARMA5724510 By your code it seems you want to remove a given character, for example if string is “ABCDE” and the character is “C” so you want to output “ABDE” right?

Is that your question?

Also the indexing is 0 based so in your if statement you should use len - 1 instead of len as after removing C, len will be 4 but index till 3 is only you can access.

Also in else your loop should be i = 0 to i < leng(again the same 0 based indexing).

If your doubt is cleared mark it resolved bro!