// Naomi Jones
// Survey, Summer 2025
// July 11, 2025
// Assignment 7 - Java
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main
(String args
[]){ int numbers[]= {1,5,-9,12,-3,89, 18,23,4,-6};
// Added try and catch exception handler for out of bounds array index.
try {
// Find minimum (lowest) value in array using loop
System.
out.
println("Minimum Value = " + getMinValue
(numbers
));
// Find maximum (largest) value in array using loop
System.
out.
println("Maximum Value = " + getMaxValue
(numbers
));
// Determine the average of all element values in array using loop
// Call getAvgValue and print the average
System.
out.
println("Average Value = " + getAvgValue
(numbers
));
// Call getMedianValue and print the median
System.
out.
println("Median Value = " + getMedianValue
(numbers
));
// Sort the numbers in the array and print the sorted array
System.
out.
print("Sorted Array: "); for (int num : numbers) {
}
System.
out.
println("Error: Out of bounds array index."); }
}
// Find maximum (largest) value in array using loop
public static int getMaxValue(int[] numbers){
int maxValue = numbers[0];
// Add loop checking each array element against current maxValue
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > maxValue) {
maxValue = numbers[i];
}
}
return maxValue;
}
// Find minimum (lowest) value in array using loop
public static int getMinValue(int[] numbers){
int minValue = numbers[0];
// Adds loop checking each array element against minValue
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] < minValue) {
minValue = numbers[i];
}
}
return minValue;
}
// Find the average of an array of integers
public static double getAvgValue(int[] numbers){
// Used to store the average of all elements in an array
double sum = 0;
// Loop to compute running total of all array elements
for (int i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
// Computes averages.
double average = sum / numbers.length;
return average;
}
// Finds median of an array of integers
public static double getMedianValue(int[] numbers) {
// Sorts the array.
int length = numbers.length;
if (length % 2 == 0) {
// Median formula for even numbers
return (numbers[length / 2 - 1] + numbers[length / 2]) / 2.0;
} else {
// Median formula for odd numbers
return numbers[length / 2];
}
}
} // Main