title: Using an if statement to detect words that begin and end with the same letter
body: <p>I am trying to create a program using scanner which takes input from the user and determines whether the input begins and ends with the same character.</p>
  
  <pre><code>import java.util.Scanner;
  public class L7E6{
      public static void main(String[]args){
          String word;
          Scanner keyboard = new Scanner(System.in);
  
          System.out.println("Please type a word: ");
          word = keyboard.nextLine();
  
          if (word.charAt(0).equals(word.length()-1)){
              System.out.println("The word "+word+" begins and ends with the character "+word.charAt(0));
          }
          else{
              System.out.println("The word "+word+" begins with "+word.charAt(0)+" and ends with "+    (word.length()-1)+" these characters are not the same.");
          }
      }
  } 
  </code></pre>
  
  <p>I have used <code>charAt(0)</code> and <code>.length()-1</code> to determine first and last characters previously, but it doesn't seem to be working here.</p>