The method receives two numbers per parameter, and returns an array with the odd numbers between these two numbers.
public static int[] oddNumbers(int l, int r) {
int odd[] = new int[r];
for(int i=0; i<odd.length;i++){
if(l<=r && l%2!=0){
odd[i]=l;
} l++;
}
return odd;
}
However, it is returning the zeros numbers in the array , and is to return only the odd numbers.
At this moment, if you put oddNumbers(2,5)
, the result will be: 0 3 0 5 0
How do I return only filled positions? 3 5