missing variable

advertisements

I wrote this method to take an int[]b then creates an array of int[] Per and fill it by taking each index i in b and uses another method to return an int value to be as an index of the new array Per with value of b[i], but the small and stupid problem is it says can't find symbol i in line Per [index-1]= b[i]; any idea

 public static int [] intial(int [] b)
        {
            int [] Per =new int [64];
            int index;
            for(int i=0;i<b.length;i++)

                index=itable(i);
                Per [index-1]= b[i];

            return Per;
        }


Change

for(int i=0;i<b.length;i++)

    index=itable(i);
    Per [index-1]= b[i];

to

for(int i=0;i<b.length;i++) {
    index=itable(i);
    Per [index-1]= b[i];
}

Not including the braces { } in the loop make the compiler consider the first line only as the body of the loop and since i is a loop variable it wont be visible. Including the braces changes all this and make the two statement part of the loop body.