title: Struggling with compare last 2/3/4 characters Java (repl.it 018 - Conditional Statement Practice 4)
body: <p>Dear Stackoverflow community I am Struggling with one task on repl.it (018) Conditional Statements 4</p>
  
  <p>So they want me to do that :</p>
  
  <p>Instructions from your teacher:
   For you to do:</p>
  
  <p>Given a string variable "word", do the following tests</p>
  
  <p>If the word ends in "y", print "-ies"
  If the word ends in "ey", print "-eys"
  If the word ends in "ife", print "-ives"
  If none of the above is true, print "-s"
  No more than one should be printed.</p>
  
  <p>and my code looks like this :</p>
  
  <pre><code>import java.util.Scanner;
  
  class Main {
    public static void main(String[] args) {
      Scanner inp = new Scanner(System.in);
      System.out.print("In:");
      String word = inp.nextLine();
      //DO NOT CHANGE ABOVE CODE!  Write your code below
  
      if(word.endsWith("y"){
        System.out.println("-ies");
      }
      else if(word.endsWith("ey")){
        System.out.println("-eys");
      }
      else if(word.endsWith("ife")){
        System.out.println("-ives");
      }
      else{
  
        System.out.println("-s");
      }
    }
  }
  </code></pre>
  
  <p>When I run it for example my input is :Hey</p>
  
  <p>and of course my code will go through the code and see if the first statement is correct and yes it is equal because y = y at the end and that is WRONG! </p>
  
  <p>My question is how can i let my code compare the last 2 or 3 characters so it will print out the right value when I input Hey.</p>
  
  <p>If I input Hey it should print out :</p>
  
  <p>-eys and not -ies</p>
  
  <p>Ty</p>