I've been trying to create a program that censors a word but I was having difficulty with that so I tried going back to some of the fundamental code and testing it and I am coming across an odd result.
import java.util.Scanner;
public class TextCensor
{
public static void main(String[] args)
{
        String input;
        Scanner keyboard = new Scanner(System.in);
        input = keyboard.nextLine();
        int length = input.length() - 1;
        if (length + 1 >= 3)
        {
            for (int i=0; i<(length - 1); i=i+1 )
            {
                char first = input.charAt(i);
                char second = input.charAt(i+1);
                char third = input.charAt(i+2);
                String censorCheck = "" + first + second + third;
                if (censorCheck == "tag")
                {
                    System.out.println("success");
                }
                else
                {
                    System.out.println(censorCheck);
                }
            }
        }
        else
        {
            System.out.println(input);
        }
}
}
If I input the string "adtag" I will obtain the following output:
adt
dta
tag
yet "success" will never be printed despite the fact that I have printed a censorCheck that is equal to "tag".
 
     
     
    