CS174: OOP - Drills - Array 3 Sort

Developed by Professor Tralie and Professor Mongan.


Exercise Goals

The goals of this exercise are:
  1. To do proper array indexing
  2. To allocate and populate new arrays
  3. To use conditional statements appropriately
  4. To properly define methods
Create a static method sort3Elements that takes in 3 integers and returns a 3-element array containing those integers in sorted order. For instance, if it receives the integers 7, 1, and 3, it should return the array {1, 3, 7}

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 { /** * Prints out the elements of an array, separated by commas * * @param arr The array to print */ 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[] arr1 = ArrayUtils.sort3Elements(7, 3, 1); int[] arr2 = ArrayUtils.sort3Elements(9, 1, 8); ArrayUtils.printArray(arr1); System.out.print("."); ArrayUtils.printArray(arr2); } }
Tester.main(null);

Output