When I tried to make my own class with my own method, the method was running twice. I tried turning parts of the code to find the glitch, but the method was still running twice.
Here is the class:
import java.util.Scanner;
public class TestRB
{
    private String userInput;
    private Scanner scan = new Scanner (System.in);
    public TestRB ()
    {
        run();
    }
    public void run ()
    {
        System.out.println("Please input y or n.");
        userInput = (scan.next()).toLowerCase();
        while (!userInput.equals("y") && !userInput.equals("n"))
        {
            System.out.println("Invalid input, try again.");
            System.out.println("Please type in \"y\" or \"n.\"");
            userInput = (scan.next()).toLowerCase();
        }
    }
    public boolean yOrN ()
    {
        return (userInput == "y");
    }
    public String toString()
    {
        return userInput;
    }
}
And here is the object of the method.
public class TestRunRB
{
    public static void main (String[] args)
    {
        TestRB test = new TestRB();
        test.run();
        if (test.yOrN())
            System.out.println("Yes");
        else
          System.out.println("No");
    }
}
The output is always No after I get prompted twice, regardless of whether I inputted y or n.
 
     
    