package Prac;
import java.io.*;
import java.util.*;
public class Practice {
public static void main(String [] args){
int[] test = {0,1,2,99,4,5};
int maximum = max(test);
System.out.print(maximum);
}
public static int max(int[] test1){
int max =0;
for(int i = 0; i <=test1.length;i++){
if(test1[i]>=max){
max=test1[i];
}
}
return max;
}
}
// Java doesn't show an errors until I run this program and it gives me:
//Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
//at Prac.Practice.max(Practice.java:18)
//at Prac.Practice.main(Practice.java:9)
// I am supposed to write a method that takes an array of ints as a parameter and returns the largest element of the array.