Command line arguments

 

กก

class printArgs {

  public static void main (String args[]) {

    for (int i = 0; i < args.length; i++) { 
      System.out.println(args[i]);
    }
    
  }
  
}

The name of the class is not included in the argument list

Command line arguments are passed in an array of Strings. The first array component is the zeroth.

For example, consider this invocation:

กก

% java printArgs Hello There

args[0] is the string "Hello". args[1] is the string "There". args.length is 2.

All command line arguments are passed as String values, never as numbers. Later you'll learn how to convert Strings to numbers.

List | Previous | Next