import java.io.*; public class StringGames { static InputStreamReader isr; static BufferedReader comingIn; static PrintWriter goingOut; public static void main (String [] args) throws IOException { initialiseIO(); boolean repeat; String temp; do { repeat = false; //checkEquals(); checkNumberWords(); goingOut.println("Would you like to do this again?"); temp = comingIn.readLine(); if (temp.toLowerCase().charAt(0) == 'y') repeat = true; } while(repeat); tidyUpIO(); } public static void checkNumberWords () throws IOException { String a, b; int n=0, m=0; a = getString(); b = getString(); String [] A, B; A = a.split(" "); B = b.split(" "); n = A.length; m = B.length; goingOut.println("string a has " +n+ " words."); goingOut.println("string b has " +m+ " words."); goingOut.println("comparing the third word of a with the second word of b ...."); if (A[2].equals(B[1])) goingOut.println("They're the same!!"); else goingOut.println("They're DIFFERENT!!"); } public static void checkEquals () throws IOException { String a, b; a = getString(); b = getString(); if (a.equals(b)) goingOut.println("They're the same!!"); else goingOut.println("They're DIFFERENT!!"); } public static void initialiseIO() { isr = new InputStreamReader ( System.in ) ; comingIn = new BufferedReader ( isr ) ; goingOut = new PrintWriter ( System.out , true ) ; } // end of initliseIO method public static void tidyUpIO() throws IOException { isr.close(); comingIn.close(); goingOut.close(); } // end of tidyUpIO method public static String getString () throws IOException { String temp = null; goingOut.println ( "Please enter a string" ) ; try { temp = comingIn.readLine( ) ; } catch (IOException ioe) { System.exit(1); } return temp; } // end of getInt method }