import java.io.*;

public class ReadInts
{
    public static void main( String [ ] args )
    {
        int [ ] array = getInts( );
        for( int i = 0; i < array.length; i++ )
            System.out.println( array[ i ] );
    }

    // Read an unlimited number of ints with no attempts at
    // error recovery; return an int [ ]
    public static int [ ] getInts( )
    {
        BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
        int inputVal = 0;
        int [ ] array = new int[ 5 ];
        int itemsRead = 0;
        String oneLine;

        System.out.println( "Enter any number of integers, one per line: " );
        try
        {
            while( ( oneLine = in.readLine( ) ) != null )
            {
                inputVal = Integer.parseInt( oneLine );
                if( itemsRead == array.length )
                    array = resize( array, array.length * 2 );
                array[ itemsRead++ ] = inputVal;
            }
        }
        catch( Exception e ) { }  // No error handling
        System.out.println( "Done reading" );
        return resize( array, itemsRead );
    }

    // Resize an int[ ] array; return new array
    public static int [ ] resize( int [ ] array, int newSize )
    {
        int [ ] original = array;
        int numToCopy = Math.min( original.length, newSize );

        array = new int[ newSize ];
        for( int i = 0; i < numToCopy; i++ )
            array[ i ] = original[ i ];
        return array;
    }
}
