Reverse.java


Below is the syntax highlighted version of Reverse.java.


/*************************************************************************
 *  Compilation:  javac Reverse.java
 *  Execution:    java Reverse args1 args2 args3 . . .
 *
 *  % java Reverse Alice Bob Carol Dave  
 *  args[]
 *  ---------------------------------------
 *  Alice
 *  Bob
 *  Carol
 *  Dave
 *
 *  Array returned by reverse1(args)
 *  ---------------------------------------
 *  Dave
 *  Carol
 *  Bob
 *  Alice
 *
 *  args[] did not change
 *  ---------------------------------------
 *  Alice
 *  Bob
 *  Carol
 *  Dave
 *
 *  args[] after calling reverse2(args)
 *  ---------------------------------------
 *  Dave
 *  Carol
 *  Bob
 *  Alice
 *
 * (Web Exercise 2.1.35)
 *************************************************************************/

public class Reverse {

    // return a reversed copy of the original String array 
    public static _________ reverse1(__________________________________) {







    }

    // reverse the argument array
    public static ________ reverse2(_______________________________) {







    }


    // print the entries in the array a[] to standard output
    public static void show(String[] a) {
        for (int i = 0; i < a.length; i++) {
            StdOut.println(a[i]);
        }
    }

    public static void main(String[] args) { 

        // original array
        StdOut.println("args[]");
        StdOut.println("---------------------------------------");
        show(args);
        StdOut.println();

        // create a new array that is the reverse of args[]
        StdOut.println("Array returned by reverse1(args)");
        StdOut.println("---------------------------------------");
        String[] reverse = reverse1(args);
        show(reverse);
        StdOut.println();

        // args[] did not change
        StdOut.println("args[] did not change");
        StdOut.println("---------------------------------------");
        show(args);
        StdOut.println();

        // args[] after calling reverse2(args)
        StdOut.println("args[] after calling reverse2(args)");
        StdOut.println("---------------------------------------");
        reverse2(args);
        show(args);
        StdOut.println();

    }
}