/** Add.java -- add up the integers on the command line * It turns out that "args" is the name of an array of Strings. * For each argument, we'll extract the integer from it, then accumluate * the sum. * We assume that all the command-line arguments are integers - we don't * do any error checking. * One interesting feature about this simple program is that we don't * use a BufferedReader for input -- all our input is from the command line. */ public class Add { public static void main(String [] args) { int i, sum = 0; for (i = 0; i < args.length; ++i) sum += Integer.parseInt(args[i]); System.out.printf("The sum is %d.\n", sum); } }