// Helene Martin, CSE 143 // Reverses the words found in a file. This program is bad because we // are limited to a 1000-word file and for smaller files, we create an // unecessarily large array. import java.util.*; import java.io.*; public class ReverseFileBad { public static void main(String[] args) throws FileNotFoundException { String[] allWords = new String[1000]; int wordCount = 0; Scanner input = new Scanner(new File("words.txt")); while (input.hasNext()) { String word = input.next(); allWords[wordCount] = word; wordCount++; } for (int i = wordCount - 1; i >= 0; i--) { System.out.println(allWords[i]); } } }