001package edu.pdx.cs410J.lang; 002 003/** 004 * This program demonstrates exception handling by reading two 005 * integers from the command line and prints their sum. 006 */ 007public class AddTwo { 008 009 /** 010 * Prints the sum of two numbers from the command line. 011 */ 012 public static void main(String[] args) { 013 int anInt = 0; // Must initialize these guys 014 int anotherInt = 0; 015 016 try { 017 anInt = Integer.parseInt(args[0]); 018 019 } catch (NumberFormatException ex) { 020 System.err.println("Invalid integer: " + args[0]); 021 System.exit(1); 022 } 023 024 try { 025 anotherInt = Integer.parseInt(args[1]); 026 027 } catch (NumberFormatException ex) { 028 System.err.println("Invalid integer: " + args[1]); 029 System.exit(1); 030 } 031 032 System.out.println(anInt + " + " + anotherInt + " = " + 033 (anInt + anotherInt)); 034 } 035}