Java I/O How to - Print out the console parameters








Question

We would like to know how to print out the console parameters.

Answer

/*from w ww . ja va  2 s. com*/
public class Main {
  public static void main(String[] args) {
    if (args.length == 0) {
      System.out.println("No arguments");
    } else {
      System.out.println("Arguments:");
      for (int i = 0; i < args.length; i++) {
        System.out.println(args[i]);
      }
    }
  }
}

The code above generates the following result.