Java for students logo
Explore the English language on a new scale using AI-powered English language navigator.

Print command-line arguments

Abstract

Java program, printing its command-line arguments.

Source code

PrintCommandLineArguments.java

public class PrintCommandLineArguments {

      public static void main(String[] args) {

            System.out.println("Command-line arguments:");

            for (String arg : args) {

                  System.out.println(arg);

            }

      }

}

Download PrintCommandLineArguments.java

Sample run

java PrintCommandLineArguments arg1 arg2 arg3 "complex arg 4"

Command-line arguments:

arg1

arg2

arg3

complex arg 4

 

Partners Ads