Back

import java.util.*;
public class example6 {

   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);

      String oneLine;
      StringTokenizer str;

      int x, y;

      System.out.println("Enter 2 integers on one line:");

      try
      {
         oneLine = sc.nextLine();
         if (oneLine == null)
            return;

         str = new StringTokenizer (oneLine);
         if (str.countTokens() !=2)
         {
            System.out.println("Error: Please enter two integers");
            return;
         }

         x = Integer.parseInt(str.nextToken() );
         y = Integer.parseInt(str.nextToken() );
         System.out.println("Max: " + Math.max(x, y));
      }
      catch (NumberFormatException e)
      {
         System.err.println("Error: Need Two Ints" );
      }
   }
}

Top