// Allison Obourn // CSE 143 - lecture 1 // prints out tokens from a file in reverse order, removes plurals // and demonstrates how to use ArrayLists. import java.util.*; import java.io.*; public class Reverse { public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new File("words.txt")); ArrayList words = new ArrayList(); // reads words from a file while(scan.hasNext()) { words.add(scan.next()); } // prints words from a file in reverse order for(int i = words.size() - 1; i >= 0; i--) { System.out.println(words.get(i)); } // removes all words that end in s for(int i = 0; i < words.size(); i++) { if(words.get(i).endsWith("s")) { words.remove(i); i--; } } System.out.println(words); // creates a list of numbers demonstrating wrapper classes ArrayList a = new ArrayList(); a.add(3); int b = a.get(0); } }