import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; public class LinesInArray{ public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out, true); out.println("Please type some words. (Press q when you are done.)"); String[] words = new String[100]; int i = 0; try { do { words[i] = in.readLine(); i++; } while ((i != 100) && (!words[i-1].equals("q"))); }//try catch (Exception e) { out.println("Sorry, I am not working properly: " + e); }//catch int numWords = i-1; // Find the largest word. String longest = words[0]; // For each word for (int j = 1; j <= numWords; j++) { // If words[j] is longer than longest, if (words[j].length() > longest.length()) { // update longest longest = words[j]; } // if words[j] is longer than longest } // for each word out.println("The longest word you entered is '" + longest + "'"); // Find the alphabetically first word. String alphabeticallyFirst = words[0]; for (int j = 1; j <= numWords; j++) { if (alphabeticallyFirst.compareTo(words[j]) > 0) { alphabeticallyFirst = words[j]; } } // for out.println("The alphabetically first word you entered is '" + alphabeticallyFirst + "'"); // That's it, we're done System.exit(0); } // main(String[]) /**To get the largest string public static void larger(String[] words){ for ( i=0; i < words.length; i++) { if (compareTo (words[i], words[i+1]) > 0) larger (words[i]); else larger (words[i+1]); }//for larger(words[i+1]); */ }// class LineInArray