import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; /* Prints out all the words in words.txt, where any word that ends in "s" * is completely capitalized. */ public class CapitalizeEndingInS { /* Reads in the words from the file filename */ public static ArrayList readFile(String filename) throws FileNotFoundException { Scanner input = new Scanner(new File(filename)); ArrayList words = new ArrayList(); while (input.hasNext()) { String word = input.next(); words.add(word); } return words; } public static void main(String[] args) throws FileNotFoundException { ArrayList list = readFile("words.txt"); /* Print out all the words in list, but make sure to capitalize * any word ending in "s" */ for (int i=0; i < list.size(); i++) { if (list.get(i).endsWith("s")) { System.out.println(list.get(i).toUpperCase()); } else { System.out.println(list.get(i)); } } } }