I have an int array. I want to loop thru the 'nums' array and create 2 arrays for odd numbers and even numbers
int[] nums = {11, 5, 2, 60, 32, 9, 21, 4};
The expected result should be 2 arrays. One array should have even numbers and another array should have odd numbers. but I get outofboundexception error. can't figure out what is wrong
public class ExamReview {
public static void main(String[] args) {
int[] nums = {11, 5, 2, 60, 32, 9, 21, 4};
//int[] nums = {11, 5, 2};
int [] evenArray= new int[4];
int [] oddArray= new int[4];
int sizeofarray = nums.length;
for(int i = 0; i< nums.length; i++){
if(nums[i] %2 == 0) {
evenArray[i] = nums[i];
}
else{
oddArray[i]= nums[i];
}
}
}