/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs
online.
*/
import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        String test="all are four or less in this";
        System.out.println("This is the string to be checked: " + test + "\n");
        censor cs = new censor ();
        System.out.println("This is the string: " + cs.censor(test));
    }
}

class censor
{
    private String test;
    StringBuffer sb=new StringBuffer(" ");
    int numberChars;
    StringJoiner sj = new StringJoiner(" ");
    boolean wordLengthGreaterFour=false;
    String converted;

    public String censor (String test)
    {
        this.test=test;
        String temp;
        StringTokenizer st = new StringTokenizer(test);
        
        while (st.hasMoreTokens())
        {
            temp=st.nextToken();
            System.out.println("Processing word: " + temp);

            if (temp.length()<=4)
            {
                numberChars=temp.length();
                
                System.out.println(numberChars);
                System.out.println("length token should be less than or equal to 4: " + numberChars);
                
                converted = temp.toString();
                System.out.println("This is the token less than or equal to 4 chars: " + converted);
                
                sj.add(converted);
                
                System.out.println("This is the current string: " + sj.toString());
                System.out.println("\n");
            }
            else
            {
                numberChars=temp.length();
                System.out.println("length token shuld be greater than 4: " + numberChars);
                
                converted = temp.toString();
                System.out.println("This is the token greater than 4: " + converted);
                
                wordLengthGreaterFour=true;
                
                for (int j=0; j<numberChars; j++)
                {
                    sb.append("*");
                }
                
                System.out.println("This is the number of *: " + sb);
                sj.add(sb);
                
                System.out.println("This is the current stringbuilder with ****: " + sb);
                
                sb.replace(0,sb.length(), "");
                
                System.out.println("This is the current stringbuilder with **** REMOVED: " + sb);
                System.out.println("This is the current string: " + sj.toString());
                System.out.println("\n");
            }
        }
        
        if (!wordLengthGreaterFour)
        {
            sj.add(test);
            return sj.toString();
        }
        return sj.toString();
    }
}