My Task:

---Example: 2 2 3 20 10 7 9 6 8 8 8 2 9 12 14 5 5 5 5 19

plateau = 6 8 8 8 2 because 8 is the longest sequence of identical

numbers where the numbers to the left and right are lower.

MY ERROR: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 500

at Lab8.main(Lab8.java:60)

int [] arr3 = new int [500]; for(int i = 0; i < arr3.length;i++){ int y = gen.nextInt(20)+1; arr3[i] = y; System.out.print(" " + y); } int tempBookend1 = 0; int tempBookend2 = 0; int tempPos1 = 0; int tempPos2 = 0; int tempLength = 0; int tempType = 0; int bookend1 = 0; int bookend2 = 0; int pos1 = 0; int pos2 = 0; int length = 0; int type = 0; for(int i = 0; i < arr3.length;i++){ for(int j = 1; j <= arr3.length-2;j++){ if( tempBookend1 < arr3[tempPos1] && tempBookend2 < arr3[tempPos2] && tempLength > length){ bookend1 = tempBookend1; bookend2 = tempBookend2; pos1 = tempPos1; pos2 = tempPos2; length = tempLength; type = tempType; } else if(arr3[i] == arr3[i+1]){ // I get an error here tempPos1 = i; tempBookend1 = arr3[i-1]; } else if(arr3[i] != arr3[i+1]){ // I get an error here tempPos2 = i; tempBookend2 = arr3[i+1]; tempType = arr3[i]; tempLength = (tempPos2 - tempPos1); } } }