STRINGS

4. Program to remove all occurrences of a given character from input String?

            lass Main{
                static String removeChar(String str, char ch){
                    String newstr = "";
                    char c;
                    for(int i = 0; i < str.length(); i++){
                        c = str.charAt(i);
                        if(c != ch){
                            newstr += c;
                        }
                    }
                    return newstr;
                }
                public static void main(String[] args){
                    System.out.println("Removing p from apple");
                    System.out.println(removeChar("apple", 'p'));
                }
            }
        

OUTPUT

            Removing p from apple
            ale