n
isn't the loop control variable, it's a.length
which is an out of bounds index. You probably meant
sum += a[i] * b[i];
And, although it does not matter directly, you probably meant your for
-loop to be
for (int i = 0; i < n; i++)
(I would assume that's the reason you have n
in the first place.)