import java.util.Arrays;
public class MyClass {
public static int getTotalOddNumbers(int array[]) {
int totalOdd = 0;
for (int i : array) {
if (i % 2 != 0) {
totalOdd++;
}
}
return totalOdd;
}
public static void setOddNumbers(int array[], int oddNumbers[]) {
int i = 0;
for (int num : array) {
if (num % 2 != 0) {
oddNumbers[i++] = num;
}
}
}
public static void main(String args[]) {
int array[] = {2, 5, 1, 9, 8, 0, 4, 7, 3};
int oddNumbers[] = new int[getTotalOddNumbers(array)];
setOddNumbers(array, oddNumbers);
System.out.println(Arrays.toString(oddNumbers));
}
}
/*
run:
[5, 1, 9, 7, 3]
*/