CS174: OOP - Drills - Creating the reverse of an array

Developed by Professor Tralie and Professor Mongan.


Exercise Goals

The goals of this exercise are:
  1. To do proper array indexing
  2. To use loops in concert with arrays
  3. To allocate and populate new arrays
Fill in the method getReverseArray in ArrayUtils.java to return a new array which is the reverse of a given array. For example, the array {0, 5, 2, 3} would turn into the array {3, 2, 5, 0}.

Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is ctralie (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit)

Netid
Clicking Run below will check your work and, if it passes, will submit your work automatically. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail!

ArrayUtils.java

public class ArrayUtils { public static int[] getReverseArray(int[] arr) { /** TODO: Fill in your code here to create the reverse array **/ return {}; } public static void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.print(arr[i]); if (i < arr.length-1) { System.out.print(","); } } } }

Tester.java

public class Tester { public static void main(String[] args) { int[] arr0 = {0, 5, 10, 0, 3, 4, 0, 1}; int[] arr0rev = ArrayUtils.getReverseArray(arr0); int[] arr1 = {0, 0, 1, 1, 1, 1, 3}; int[] arr1rev = ArrayUtils.getReverseArray(arr1); ArrayUtils.printArray(arr0rev); System.out.print("."); ArrayUtils.printArray(arr1rev); } }
Tester.main(null);

Output