import java.io.*; public class ArrayPlay { static InputStreamReader isr; static BufferedReader comingIn; static PrintWriter goingOut; static boolean ok; public static void main ( String [] args ) throws IOException { initialiseIO(); int [] store, temp = new int[10000]; int i = 0; ok = true; goingOut.println("Please enter some integers for me to play with," + " with one on each line."); do { // gathering data from the keyboard temp[i] = getInt(); i++; } while (ok); i--; // since the last pass through this (a non-number) shouldn't count! store = new int[i]; // we'll now shrink wrap the array for (int n = 0; n < store.length; n++) store[n] = temp[n]; temp = null; // to save space goingOut.println("you entered " +i+ " numbers."); printArray(store); squareThings(store); printArray(store); tidyUpIO(); } public static void squareThings ( int [] array ) { for (int n = 0; n < array.length; n++) array[n] *= array[n]; } public static void printArray (int [] array) { for (int n = 0; n < array.length; n++) goingOut.println(array[n]); } 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 int getInt () throws IOException { int temp = 0; //goingOut.println ( "Please enter an integer" ) ; try { temp = Integer.parseInt ( comingIn.readLine( ) ) ; } catch (NumberFormatException nfe) { ok = false; } return temp; } // end of getInt method }