why i am geeting this error
<p>I am trying to build a matrix with row and collumn having values such as "aaa" for aligning purposes.but when i run it i get an error can anyone tell me where i am going wrong and how to fix it.below is my code</p>

<pre><code>     public class compute_matrix {
static String seq1="aaa";
 static String seq2="aaa";
 static int[][] matrix;
 static int max_row;
 static int max_col;
private static int match_reward=1;
private static int mismatch_penalty= -1;
private static int gap_cost= -1;
private static boolean case_sensitive;

private static boolean isCaseSensitive() {
  return case_sensitive;
}

private static int max(int ins, int sub, int del, int i) {
    if (ins &gt; sub) {
        if (ins &gt; del) {
            return ins &gt; i? ins : i;
        } else {
            return del &gt; i ?del : i;
        }
    } else if (sub &gt; del) {
        return sub&gt; i ? sub : i;
    } else {
        return del &gt; i ? del : i;
    }
}

 protected char sequence[];




   public static void main(String args[]){
    int r, c, rows, cols, ins, sub, del, max_score;

    rows = seq1.length()+1;
    cols = seq2.length()+1;

    matrix = new int [rows][cols];

    // initiate first row
    for (c = 0; c &lt; cols; c++)
        matrix[0][c] = 0;

    // keep track of the maximum score
    max_row = max_col = max_score = 0;

    // calculates the similarity matrix (row-wise)
    for (r = 1; r &lt; rows; r++)
    {
        // initiate first column
        matrix[r][0] = 0;

        for (c = 1; c &lt; cols; c++)
        {
                        sub = matrix[r-1][c-1] + scoreSubstitution(seq1.charAt(r),seq2.charAt(c));
            ins = matrix[r][c-1] + scoreInsertion(seq2.charAt(c));

            del = matrix[r-1][c] + scoreDeletion(seq1.charAt(r));

            // choose the greatest
            matrix[r][c] = max (ins, sub, del, 0);

            if (matrix[r][c] &gt; max_score)
            {
                // keep track of the maximum score
                max_score = matrix[r][c];
                max_row = r; max_col = c;
            }
        }
    }

     }

private static int scoreSubstitution(char a, char b) {
   if (isCaseSensitive())
        if (a == b)
            return match_reward;
        else
            return mismatch_penalty;
    else
        if (Character.toLowerCase(a) == Character.toLowerCase(b))
            return match_reward;
        else
            return mismatch_penalty;
}

private static int scoreInsertion(char a) {
 return gap_cost;
}

private static int scoreDeletion(char a) {
    return gap_cost;
}
public char charAt (int pos)
{
    // convert from one-based to zero-based index
    return sequence[pos-1];
}

  }
</code></pre>

<p>and my error is displaying this</p>

<pre><code>              Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3
    at java.lang.String.charAt(String.java:695)
    at compute_matrix.main(compute_matrix.java:67)
</code></pre>

<p>Java Result: 1</p>
