How can I pick out the odd numbers and even numbers from a given array and then store them in another array? The flow is: the odd numbers will go to the odd[] array while the even numbers will go to the even[] array??
Here's my code, I'm not sure if this is correct since it somewhat stores and prints a mix of zeros and even numbers, no presence of odd numbers.....
int[] num = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int[] odd = new int[10];
int[] even = new int[10];
for (int i = 0; i < num.length; i++) { // For odd numbers
if (num[i] % 2 != 0) {
num[i] = odd[i];
}
System.out.println(num[i] + " ");
}
for (int j = 0; j < num.length; j++) { // For even numbers
if (num[j] % 2 == 0) {
num[j] = even[j];
}
System.out.println(num[j] + " ");
}