import java.io.*; import java.util.StringTokenizer; // Read two integers and output the maximum. public class MaxTest { public static void main( String [ ] args ) { BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); System.out.println( "Enter 2 ints on one line: " ); try { String oneLine = in.readLine( ); StringTokenizer str = new StringTokenizer( oneLine ); if( str.countTokens( ) != 2 ) { System.err.println( "Error: need two numbers" ); return; } int x = Integer.parseInt( str.nextToken( ) ); int y = Integer.parseInt( str.nextToken( ) ); System.out.println( "Max: " + Math.max( x, y ) ); } catch( IOException e ) { System.err.println( "Error: unexpected I/O exception" ); } catch( NumberFormatException e ) { System.err.println( "Error: numbers were not both ints" ); } } }