/************************************************************************* * Name: * Login: * Precept: * * Description: Shows off two ways to reverse an array and what happens * after each. * * Dependencies: StdOut.java * * Example: * % 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 (This is booksite Web Exercise 2.1.35.) *************************************************************************/ public class Reverse { // TO DO: Write a method reverse1() that takes a String array as an argument, // and returns a new String array which holds the reverse of the argument array. // DO NOT ALTER the original array. // return a reversed copy of the original String array public static _________ reverse1(__________________________________) { } // TO DO: Use the code from page 89 or Booksite Ex.1.4.4 to write a function // reverse2() to reverse the elements in a String array. The array is an // argument of the method. The method does not return anything. It reverses // the original array. // 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(); } }