Im doing a thing for a thing and I have to "Multiply each element in list2 by its element index number and place the value in array list1." and so my code is
public static void main(String[] args) {
int List1 []= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
int List2 []= {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int L1= 0;
int L2= 0;
for( L2=0 ;L2<List2.length;L2++) {
List2[L2]= (int) (100*Math.random());
System.out.print(" "+List2[L2]);
}//end of list2 for loop
System.out.println("");
for( L1 = 0;L1<List1.length;L1++)
{
List1[L1]= List2[L2]*L2;
System.out.print(" "+List1[L1]);
}//end of list1 for loop
)
and it throws this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20"
Aucun commentaire:
Enregistrer un commentaire