Remove preoccured characters from the sentence remove extra spaces - Java Quiz Question

Write a program to remove the preoccured characters from the given sentence. If the all the letters of word get removed, then do not include the space before the word. Do not use the methods replace or replaceAll.

Input (String) Output (String)
Hello How are you Helo w ar yu
I am a good boy I am god by
Sun rises in the east Sun rie th a
Good is good so long as it is good God is ln a t
Indians love cricket Indas love crkt
Learn Java with Merit Campus Learn Jv with M Cpus

class RemovePreoccuredCharactersAdvanced

{    public static void main(String s[])
        String sentence = "Sun rises in the east";
        System.out.println("After removing pre occured characters : " + removePreoccuredCharacters(sentence));


public static String removePreoccuredCharacters(String sentence) {
//Write code here to remove the preoccured characters