Common array errors

  1. studentNum <= grades.length
    if studentNum = grades.length, then the array element with index
    grades[studentNum] causes an array out of bounds exception.
    Since the indices start at 0, this means they only go to the arrays length - 1.

  2. studentNum may not have been initialized

  3. grades(studentNum)
    java would think is a call to a method grades with a parameter studentNum.
    It should be looking at indices in an array...arrays use square brackets. SO

    grades[studentNum] = "A";

    is the correct syntax for putting the string value of "A" into the array grades at location studentNum.

    If this were the instantiation of the array grades
    String [] grades = new String[4];
    then when this loop is done,

the array would look like:

ARRAY grades:A AA A
INDICES0 1 2 3