Keyboard Input Example

import java.io.*;
/**
 * Input 2 integers from the keyboard and output their sum
 */
public class KeyboardExample {

  public static void main(String[] args) {
  
    String line = null;
    
    try {
  
      BufferedReader br = 
      
                new BufferedReader(new InputStreamReader(System.in));
     
      System.out.print("Enter an integer: ");
      
      System.out.flush();
      
      line = br.readLine();
      
      int firstInteger = Integer.parseInt(line);
      
      System.out.print("Enter an integer: ");
      
      System.out.flush();
      
      line = br.readLine();
      
      int secondInteger = Integer.parseInt(line);
      
      System.out.println(firstInteger + " + " + secondInteger + 
                         " = " +    (firstInteger + secondInteger));
   }
   
   catch (IOException e) {
   
     System.out.println(e);
   }
   
   catch (NumberFormatException e) {
   
     System.out.println("You must enter an integer!");
   } 
 }
}