10) A statement that creates invokes findAll() based on the argument 8 and assigns this to a new array
11) A print statement that prints out the array created in the above step.
Which i did with the following bit of code in my driver
ArrayMethods arrayTwo = new ArrayMethods();
arrayTwo.findAll(7);
System.out.println(arrayTwo);
but i am receiving an error from this next bit of code in my class for out of bounds
public int[]findAll(int key)
{
int index = 0;
int count = 0;
for(int i : a)
{
if(a[i] == key) //this is where the error is being highlighted
{
count++;
}
}
int[]array = new int[count];
if(count!= 0)
{
for(int i=0;i<a.length;i++)
{
if(a[i]==key)
{
array[index]=i;
index++;
}
}
}
else
{
System.out.println("Key chosen doesnt exist in array");
}
return array;
}
any help with what im doing wrong here would be much appreciated :).