I'm trying to identify multiples of 3 from an input array and insert those multiples in to output array.Using a count variable I can declare the output array. But then how can I insert multiples in to output array?.
public class MultipleOfThreeInAnArray {
static int count;
static int[] result;
public static void choseMultiplesOfThree(int[] input) {
for (int i = 0; i < input.length; i++) {
if (input[i] % 3 == 0) {
count++;
// insert into output array?
int[] result = new int[count];
}
}
public static void main(String[] args) {
int[] input = { 3, 2, 5, 6, 9, 30 };
choseMultiplesOfThree(input);
}
}