public class FunctionPractice {
    /*
    * Prints the characters of a string,
    * with one character per line.
    *
    * Input: String s
    * Output: (nothing)
    */
    public static void printChars(String s) {
        for (int i = 0; i < s.length(); i++) {
            char current = s.charAt(i);
            System.out.println(current);
        }
    }

    /*
    * Computes the sum of all values 
    * in an array of doubles.
    *
    * Input: arr, the array of doubles
    * Output: the sum
    */
    public static double sumOfArray(double[] arr) {
        double sum = 0.0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    /*
    * Computes the average of all values 
    * in an array of doubles.
    *
    * Input: arr, the array of doubles
    * Output: the average value
    */
    public static double meanOfArray(double[] arr) {
        double sum = sumOfArray(arr);
        return sum / arr.length;
    }

    /*
    * Replaces each int in an array with
    * its absolute value.
    *
    * Input: arr, the array of ints
    * Output: (nothing)
    */
    public static void absoluteValue(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Math.abs(arr[i]);
        }
    }

    public static void main(String[] args) {
        // printChars("Hello, world!");

        // double[] meanNumbers = {-1.5, 0, 1.5}; // should have average 0
        // System.out.println(meanOfArray(meanNumbers));

        // int[] absNumbers = {0, -17, 3, -4};
        // absoluteValue(absNumbers);
        // for (int i = 0; i < absNumbers.length; i++) {
        //     System.out.println(absNumbers[i]);
        // }
    }
}