CS174: OOP - Drills - Array Min Index
Developed by Professor Tralie and Professor Mongan.
Exercise Goals
The goals of this exercise are:- To do proper array indexing
- To use loops in concert with arrays
- To keep track of multiple auxiliary variables in a loop
- To properly define methods
getMinIndex
takes in an array of doubles and returns the index of the minimum element in the array. You must handle the following two special cases: - If there are ties, it should return the lowest index among the ties
- If the array is empty, your program should return 0 without crashing
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 |
ArrayUtils.java
public class ArrayUtils {
// TODO: Add your method here
}
Tester.java
public class Tester {
public static void main(String[] args) {
int[] arr0 = {3, 5, 0, 8, 0, 2};
int min0 = ArrayUtils.getMinIndex(arr0);
int[] arr1 = {9, -3, 4, -3, 2, 5, 3, 2};
int min1 = ArrayUtils.getMinIndex(arr1);
int[] arr2 = {};
int min2 = ArrayUtils.getMinIndex(arr2);
System.out.print(min0);
System.out.print(".");
System.out.print(min1);
System.out.print(".");
System.out.print(min2);
}
}
Tester.main(null);