2

I am currently trying to use a .txt file in java and I want to efficiently process the whole file so for instance, words that start with a capital letter and end with "ed" or "t" are printed out. I have tried implementing a "for loop" to search for the words to see if they are over the length of 5 and have the ending of "ed" or "t" I have tried using indexOf to help me find the endings.

public void word(String word)
{
    if(word.length() == 5 || word.length() > 5)
    {
        if(word.indexOf("ed"))
        word = specificWord;
        System.out.println(specificWord);
    }
}

However, I am having difficulties making it process capital letters. I would appreciate if anyone could be able to assist me and give me a hint on how to resolve the issue. Thank you very much. -Jeff

Jeff C
  • 43
  • 4
  • 2
    Side note: `word.length() == 5 || word.length() > 5` is equivalent to `word.length() >= 5` – Christian Tapia Jan 18 '16 at 22:48
  • `if (word.charAt(0) == Character.toUpperCase(word.charAt(0)) && word.endsWith("ed") && (word.endsWith("ed") || word.endsWith("t"))) {`? or `if (Character.isUpperCase(word.charAt(0)) && (word.endsWith("ed") || word.endsWith("t"))) {`? – MadProgrammer Jan 18 '16 at 22:51
  • can u describe exactly what is not working ? and what this method suppose to do ? – chenchuk Jan 18 '16 at 22:51
  • Here's a way to check if it stats with a capital letter: `"ABCDEFGHIJKLMNOPQRSTUVWXYZ".contains(word.charAt(0));`. Could be more efficient, but it works. – John S. Jan 18 '16 at 22:57

0 Answers0