This program is supposed to find Max and Min in an array,
but it send error:
 "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 23
    at Mine_EnhancedForLoop.main(Mine_EnhancedForLoop.java:17)"
Does anyone know, what the problem is?
public class Mine_EnhancedForLoop {
    public static void main(String[] args) {
            int[] array1 = {23, 98, 10, 1, 45, 2, 7, 90};
            int max = array1[0];
            int min = array1[0];
            for (int i : array1){
                if (array1[i] > max)
                    max = array1[i];
                else if (array1[i] < min)
                    min = array1[i];
            }
            System.out.println("Maximum is: " + max);
            System.out.println("Minimum is: " + min);
    }
}
 
     
     
     
     
     
    