previous | start | next

Example: Integer Input with Scanner

        import java.util.Scanner;

    1   public class ScannerInputTester
    2   {
    3      public static void main(String[] args)
    4      {
    5        Scanner in;
    6        int first, second, larger;
    7   
    8        in = new Scanner(System.in);
    9        System.out.print("Enter first integer: ");
   10        first = in.nextInt();
   11        System.out.print("Enter second integer: ");
   12        second = in.nextInt();
   13        larger = Math.max(first, second);
   14        System.out.printf("The larger of %d and %d is %d\n", 
   15                           first, second, larger);
   16     }
   17   }


previous | start | next