I seen this question on Codility. write a function:
class solution{ public int[] solution(int X, int Y);}
that given X=0 and Y=100, return an array of integers that are odd between 0 and 100.
I wrote the following code:
import java.util.*;
public class Solution{
int X = 0;
int Y = 10;
ArrayList<Integer> arrli = new ArrayList<Integer>();
public int[] solution( int X, int Y){
for(int i = X; i<=Y;i++){
if(i % 2 != 0){
arrli.add(i);
}
}return (int[])arrli.toArray();
}
}
And got the below error:
error: incompatible types: Object[] cannot be converted to int[]
}return (int[])arrli.toArray();