-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxTest.java
executable file
·41 lines (36 loc) · 1.17 KB
/
MaxTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class MaxTest
{
public static void main( String [ ] args )
{
BufferedReader in = new BufferedReader( new
InputStreamReader( System.in ) );
String oneLine;
StringTokenizer str;
int x;
int y;
System.out.println( "Enter 2 ints on one line: " );
try
{
oneLine = in.readLine( );
if( oneLine == null )
return;
str = new StringTokenizer( oneLine );
if( str.countTokens( ) != 2 )
{
System.out.println( "Error: need two ints" );
return;
}
x = Integer.parseInt( str.nextToken( ) );
y = Integer.parseInt( str.nextToken( ) );
System.out.println( "Max: " + Math.max( x, y ) );
}
catch( IOException e )
{ System.err.println( "Unexpected IO error" ); }
catch( NumberFormatException e )
{ System.err.println( "Error: need two ints" ); }
}
}