Hi everybody,

I'm a beginner in java programing, and I've got a little problem. I'm trying to write a little program which got as input a string as food(chocolate(good)),(caramel(youmi)). And I want to get as output a string as food((chocolate([good])),(caramel([youmi]))) i.e. insert an opening bracket [ after the last open parenthesis and a closing bracket before the first closing parenthesis each substring before the comma. My code, but i't gives me the error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at me.Main.main(Main.java:29)

But I can't find how to fix it can anyone help me please....
Thank you,

Here is my code
Java Code:
public class Main {

* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here 
     String input= "batata(zrodiya(macaroun))";
     String[] sentences = input.split(",");

    for (int i = 0; i < sentences.length; i++) {
      int l=0;
      char[] sentenceTab = sentences[i].toCharArray();
      int leng=sentences.length+4;

      char[] sentenceTab1 = sentences[leng].toCharArray();

      char c1=' ';

      int k;
    for(k =0; k < sentenceTab.length ; k++){
     for (l=0; l<sentenceTab1.length; l++)
      { sentenceTab1[l]=sentenceTab[k];

    for (l=0; l<sentenceTab1.length+2; l++)
     { c1=sentenceTab[l];
        if  (c1==')'){
               int v = l ;
              for (l=sentenceTab1.length+2; l>0; l--)
                  {  sentenceTab1[l]=sentenceTab1[l-1];


    for (l=sentenceTab1.length+2; l>0; l--)
       {char c = sentenceTab[l-1];
          if (c== '('){
                       int j=c;
                       for (int v=sentenceTab1.length+2; v>0; v--)
                            { sentenceTab1[v]=sentenceTab1[v-1];

       sentences[i] = String.copyValueOf(sentenceTab1);

      input = "";
      for (int i = 0; i < sentences.length-1; i++) 
                                input += sentences[i]+",";