Arguments with Spaces

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

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

A command line argument that contains spaces is surrounded by quotes:

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 12:

(Thought Question: ) Are the data on a list always processed in order?