4576l1.txt

Listing 1. Test.java

/* Java Test class.

   This class defines a single method, "main", which is meant to be
   invoked from the command line.

 */

class Test 
{
    /**
     * main()
     *
     * If there are no arguments, main() prints "Hello, world" to STDOUT.
     * If there are arguments, main() prints them to STDOUT.
     */

    public static void main (String[] args)
    {
        // How many arguments did we receive?
        if (args.length == 0)
            {
                System.out.println ("Hello, world");
            }
        // If we received any arguments, iterate through them
        else
            {
                for (int index = 0; index < args.length; index++)
                    {
                        // Display the argument
                        System.out.print (args[index]);

                        // Separate arguments with a vertical bar
                        if ((index + 1) < args.length)
                            {
                                System.out.print("|");
                            }
                    }

                // Print a newline after displaying the final argument
                System.out.println("");
            }
    }
}