go to previous page   go to home page   go to next page highlighting

Answer:

public class InputDemo
{
  public static void main ( String[] args )
  {
    int sum = 0;
    for (int j=0; j  < args.length; j++ )
      sum += Integer.parseInt(  args[j]  );

    System.out.println( "Sum: " + sum );
  }
}

Arguments with Spaces

Put quotes around a command line argument if it contains spaces.

C:\>java SomeProgram "one argument" "another argument"

The Java system creates an array of String references if there are any on the command line. But the program is free to ignore them.


QUESTION 13:

(Thought Question: ) How can a program tell how many command line arguments it has been given?


go to previous page   go to home page   go to next page