title: Why is my method running twice?
body: <p>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. </p>
  
  <p>Here is the class:</p>
  
  <pre><code>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") &amp;&amp; !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;
      }
  }
  </code></pre>
  
  <p>And here is the object of the method.</p>
  
  <pre><code>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");
      }
  }
  </code></pre>
  
  <p>The output is always No after I get prompted twice, regardless of whether I inputted y or n.</p>