trying to put all negative ints in array
int[] a = {1,2,3,-4,-5,-5,-9};
into separate array, this code produces 'array out of bounds' not sure why
int[] negatives(int[] a){
int count = 0;
int[] na = new int[0];
for(int i=0;i<a.length;i++){
if(a[i]<0){
count++;
na=new int[count];
a[i] = na[i];
}
}
System.out.print(na.length);//<-shows correct size for resulting array
return na;
}
console output for na.length gives correct size. thanks any help