> Compsci String help?

Compsci String help?

Posted at: 2014-12-18 
Try adding this statement:

System.out.println ("Ending="+ending);

I am writing a program that tells you if a word ends in -tion. I have to use substring. This is what I have for that part so far. I don't understand why it is not working. Everytime it says the word deos not end in -tion.

System.out.println("Enter a word and I will tell you if it ends in -tion");

String word1 = sc.next();

if (!word1.equalsIgnoreCase("stop"))

{



String ending = word1.substring((word1.length() - 4), (word1.length() -1));

if (ending.equalsIgnoreCase("tion"))

System.out.println("This word ends with -tion.");

else

System.out.println("This word does not end with -tion");

}

else

System.out.println("Stop");

The program is supposed to stop if you enter stop.