My code is generating Array Index out of bounds Exception after creating a array of 10 numbers that go from 0 to 99. Any help would be appreciated.
Thanks
public class SwapMaxMin { public static void main(String[] args) { // declare an integer array with 10 elements int [] myScore = new int [10]; int i; // initialize an array with random numbers for (i = 0; i < myScore.length; i++) myScore[i] = (int)(Math.random()*100); // print an array for (i = 0; i < myScore.length; i++) System.out.println("myScore[" + i + "]= " + myScore[i]); int max = myScore[0]; int indexOfMax = 0; for ( i = 0; i < myScore.length; i++); if (myScore[i] > max){ max = myScore[i]; indexOfMax = i; } int min = myScore[0]; int indexOfMin = 0; for( i = 0; i < myScore.length; i++); if (myScore[i] < min) { min = myScore[i]; indexOfMin = i; } System.out.println("The largest number is " + max + " and at [ " + indexOfMax + " ] " ); System.out.println("The smallest number is " + min + " and at [ " + indexOfMin + " ] " ); } }