/** * This program analyzes temperature data for Salem, OR, 1928-2005 * The data was downloaded from http://www.nws.noaa.gov/climate/local_data.php?wfo=pqr * The daily temperatures were averaged within each month to give the values in the * data file aveMonthlyTemps.txt */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Arrays; public class FiveLetterWordsSkeleton { public static String[] words = new String[6952]; public static void main(String[] args) { readFile("words5.txt"); //printWords(); //String w = getWord(); } public static String getWord() { Scanner in = new Scanner(System.in); String word = ""; while(true) { System.out.println("Enter a 5 letter word."); word = in.next(); if (word.length() != 5) System.out.println("Your word is not 5 letters long. Try again."); else break; } System.out.println("You entered: " + word); return word; } /** Print out all of the data */ public static void printWords() { for (int i=0;i< words.length;i++) { if (i%15==0) System.out.print("\n"+i+": "); System.out.print(words[i] + " " ); } } /** Read 5-letter words from the file. Assumes each line of the file contains a single word. * @param filename the name of the ascii file name */ public static void readFile(String filename) { try { File inputFile = new File(filename); Scanner in = new Scanner(inputFile); int cnt = 0; while(in.hasNextLine()) { words[cnt] = in.nextLine().trim(); cnt++; } System.out.println("count = " + cnt); } catch (FileNotFoundException e) { System.out.println("File not found."); } } }