Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Assignments

CSCI125Code


ArrayUtilities.java

public class ArrayUtilities {
    
    /**
     * Prints the elements of the array on a single line with commas between.
     * E.g. if A=[1, 2, 3, 4], it should print:
     * 1, 2, 3, 4
     * 
     * Bonus points for having it not print the comma after the last element
     */
    public static void printArray(int[] A) {
        // TODO implement me!
    }
    
    /**
     * Return the sum of all of the elements in array A.
     * E.g. if A=[1, 2, 3, 4], it should return 10.
     * 
     * @return the sum of all of the elements in array A.
     */
    public static int sumArray(int[] A) {
        // TODO Implement me!
        return -1; // Here so the code compiles. Replace with real code.
    }
    
    /**
     * Return the largest element in array A.
     * E.g. if A=[31, 52, 73, 24], it should return 73.
     * 
     * @return the largest element in array A
     */
    public static int largestElement(int[] A) {
        // TODO Implement me!
        return -1; // Here so the code compiles. Replace with real code.
    }
    
    /**
     * @return true if array A has an element equal to 0, 
     * and false otherwise
     */
    public static boolean containsAZero(int[] A) {
        // TODO Implement me!
        return false; // Here so the code compiles. Replace with real code.
    }

    /**
     * Return the index of the first occurrence 
     * E.g. if A=[1, 2, 3, 4], and val=3, it should return 2 (remember, 
     * we index starting at 0), and if val=5, it should return -1.
     * 
     * @return the index of the first occurrence of val in A, or -1
     * if val is not present in A.
     */
    public int findIndexOf(int[] A, int val) {
        // TODO Implement me!
        return -1; // Here so the code compiles. Replace with real code.
    }


}