MaxTest - /* 9*/ str = new StringTokenizer( oneLine );...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.util.*; // Read two integers and output the maximum. public class MaxTest { public static void main( String [ ] args ) { /* 1*/ BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); /* 2*/ String oneLine; /* 3*/ StringTokenizer str; /* 4*/ int x; /* 5*/ int y; / /* 6*/ System.out.println( "Enter 2 ints on one line: " ); /* 7*/ try { /* 8*/ oneLine = in.readLine( );
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* 9*/ str = new StringTokenizer( oneLine ); /*10*/ if( str.countTokens( ) != 2 ) /*11*/ throw new NumberFormatException( ); /*12*/ x = Integer.parseInt( str.nextToken( ) ); /*13*/ y = Integer.parseInt( str.nextToken( ) ); /*14*/ System.out.println( "Max: " + Math.max( x, y ) ); } /*15*/ catch( Exception e ) /*16*/ { System.err.println( "Error: need two ints" ); } } }...
View Full Document

This document was uploaded on 06/13/2011.

Ask a homework question - tutors are online