why is my array out of bounds?
Hi yet again everyone,
firstly i'd like to thank everyone for all the help i have recieved in the past, without these forums, i'd have given up on java by now.
ive been slogging it out trying to get this java array chapter of my textbook done, i have created about 10 fully functional (and very simple) programs using arrays, however this one is giving me grief, i created it the same as my other ones, i get no compile errors, however i enter in the 5th element and boom, i get an error....
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at eightA.main(eightA.java:24)"
i did lots of googleing and apparently the "eightA.java:24" means the 24th line of code is causing the error.
well here is the program i am having issues with...
Code:
//Program's objective is to display the maximum value,
//entered in an array
import javax.swing.*;
public class eightA
{
public static void main(String[] args)
{
final int NUMELS=6;
int i, max;
int fmax[] = new int[NUMELS];
max = fmax[0];
String s1;
for (i = 1; i < fmax.length; i++)
{
s1 = JOptionPane.showInputDialog("Enter a number: ");
fmax[i] = Integer.parseInt(s1);
}
if (max < fmax[i])
max = fmax[i];
JOptionPane.showMessageDialog(null, "The maximum value is " + max , "message",
JOptionPane.INFORMATION_MESSAGE);
}
}