This program will print the sum of n numbers.
// sum of numbers using command line
class ArguSum
{
public static void main( String args[ ] )
{
int s = 0, len;
len = args.length;
for( int i=0 ; i<len ; i++ )
{
int x = Integer.parseInt( args[ i ] );
s = s + x;
}
System.out.println( " Sum of Command-Line Arguments ::: " + s );
}
}
Output:D:\Java Examples\java ArguSum.java 1 2 3 4 5 6 7 8 9 10
Sum of Command-Line Arguments ::: 55