/**
* A simple Java command-line application with
* exception-handling
*
* @author Ann Burroughs
* @author (mutated by) Sharon Tuttle
* @version 2-25-13
*/
public class HelloWorld318
{
/**
* prints the number of lines of greeting specified
* in the command line to System.out
*
* @param args first argument is expected to be an integer,
* the number of times to print the greeting
*/
public static void main(String args[])
{
int howManyTimes;
// try to find out how many times to print
// a greeting
try
{
howManyTimes = Integer.parseInt(args[0]);
}
// handle the exception where the 1st argument can't be
// considered to be an integer
catch (NumberFormatException exc)
{
System.out.println("HelloWorld318: was "
+ "expecting an int as "
+ "the first argument!");
howManyTimes = 1;
}
// handle the exception where NO command-line arguments
// were given (and so args[0] was an out-of-bounds
// array reference!)
catch (ArrayIndexOutOfBoundsException exc)
{
System.out.println("HelloWorld318: was expecting "
+ "a command-line int "
+ "argument!");
howManyTimes = 1;
}
// if get here, DID get a command-line integer --
// try to print greeting to screen that many times
for (int i=0; i<howManyTimes; i++)
{
System.out.println("Hello, 318 world!");
}
}
}