title: Java If else Statement on String value, with Scanner input
body: <p>I’m writing a program in the Java language, and I’m using if else statement. In this program i need to input word(s), i.e., alphabet character that has been assigned to be the values of the String data type. So that the program will print the sequential if statement, but is seems that program is not recognizing the input, because it keep printing only else statement. I need to know how to assign String values in Java language, import <code>java.util.Scanner;</code> on an if else Statement algorithm.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Compare
  {
      public static void main (String []args)
      {
  
          Scanner input = new Scanner(System.in);
          String name = “Henry”;
          System.out.println(“Enter a NAME”);
          name = input.nextLine();
  
          If ( name = “Henry”)
              System.out.println(“Welcome Henry”);
          else 
              System.out.println(“Invalid Input”);
      }
  }
  </code></pre>
  
  <p>When i run it in CMD:</p>
  
  <pre><code>C:\CODE&gt;java Compare
  Enter a NAME:
  Henry
  Invalid Input
  </code></pre>
  
  <p>It doesn’t accept the String value “Henry” thats why the else statement keeps displaying “Invalid Input”.</p>