-2

Can you please help I am new to proggraming and I don not even no what this error is caused from here is my code. I am trying to make a working Resistence formula but its not working.

 int n=kb.nextInt();
        double massiv[]=new double[n];
        for(int i=0;i<=massiv.length;i++){
            massiv[i]=kb.nextDouble();
        }
        for(int i=0;i<=massiv.length;i++){
            gr=massiv[i]*gr;
            dr=massiv[i]+dr;
        }
        Re=gr/dr;
        System.out.println(+Re);

1 Answers1

3

Arrays are 0-indexed. An array of size 2 has 2 indexes: 0 and 1. Your loops are trying to access index 2 (since they're using <=), which doesn't exist.

Replace <= in your for-loops with <

Krease
  • 15,296
  • 8
  • 50
  • 85