import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import cse143.util.*; /* Prints out all the words in words.txt in reverse order. * Then, prints them out again in order but all UPPERCASE. */ public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { Stack words = new ArrayStack(); Scanner input = new Scanner(new File("words.txt")); while (input.hasNext()) { String word = input.next(); words.push(word); } /* Copy the stack so that when we want to go through * it a second time, it still works. */ Stack copy = new ArrayStack(); while (!words.isEmpty()) { copy.push(words.pop()); System.out.println(copy.peek()); } /* When we copied the stack, it reversed; so, we need * to copy it again. */ Stack copy2 = new ArrayStack(); while (!copy.isEmpty()) { copy2.push(copy.pop()); } while (!copy2.isEmpty()) { System.out.println(copy2.pop().toUpperCase()); } } }